From 7603764b80556c9b2cd01736c2f9a143afadda16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 23 Nov 2023 21:04:11 +0100 Subject: [PATCH] Fix running the test suite when NO_COLOR is set in calling env Fix the test suite to run successfully when NO_COLOR is set in the environment in which pytest is called. This is done via adding a new fixture that "sanitizes" the environment for the duration of test run. This way pytest respects NO_COLOR while the tested library itself produces colored output as expected. --- tests/conftest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 10482b8..86c34a3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +import os + import pytest import click @@ -7,3 +9,12 @@ @pytest.fixture def runner(): return CliRunner() + + +@pytest.fixture(autouse=True) +def clean_env(): + old = dict(os.environ) + os.environ.pop("FORCE_COLOR", None) + os.environ.pop("NO_COLOR", None) + yield + os.environ = old