From 6a14458f8e9bfff8810e547ae5babf229648b199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Fri, 24 Nov 2023 16:45:42 +0100 Subject: [PATCH] Fix running tests in environment with NO_COLOR=1 Fix running the test suite when pytest is run with NO_COLOR=1 set in the environment. An fixture is autoused to ensure that the variables are removed for the scope of the test, while they are respected e.g. by pytest itself. --- colorlog/tests/conftest.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/colorlog/tests/conftest.py b/colorlog/tests/conftest.py index 65fd6d4..52ccec8 100644 --- a/colorlog/tests/conftest.py +++ b/colorlog/tests/conftest.py @@ -28,6 +28,12 @@ def assert_log_message(capsys, log_function, message, *args): return err +@pytest.fixture(autouse=True) +def clean_env(monkeypatch): + monkeypatch.delenv("FORCE_COLOR", raising=False) + monkeypatch.delenv("NO_COLOR", raising=False) + + @pytest.fixture() def reset_loggers(): logging.root.handlers = list()