Skip to content

Commit

Permalink
Reset color-related envvars for testing
Browse files Browse the repository at this point in the history
Reset color-related environment variables in a fixture to prevent them
from affecting test results.  Otherwise, some of the tests fail
e.g. if NO_COLOR is set in the calling environment.
  • Loading branch information
mgorny committed Nov 25, 2023
1 parent acab13f commit 0726ad8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testing/conftest.py
Expand Up @@ -31,6 +31,17 @@ def set_column_width(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("COLUMNS", "80")


@pytest.fixture(autouse=True)
def reset_colors(monkeypatch: pytest.MonkeyPatch) -> None:
"""
Reset all color-related variables to prevent them from affecting internal pytest output
in tests that depend on it.
"""
monkeypatch.delenv("PY_COLORS", raising=False)
monkeypatch.delenv("NO_COLOR", raising=False)
monkeypatch.delenv("FORCE_COLOR", raising=False)

Check warning on line 42 in testing/conftest.py

View check run for this annotation

Codecov / codecov/patch

testing/conftest.py#L40-L42

Added lines #L40 - L42 were not covered by tests


@pytest.hookimpl(wrapper=True, tryfirst=True)
def pytest_collection_modifyitems(items) -> Generator[None, None, None]:
"""Prefer faster tests.
Expand Down

0 comments on commit 0726ad8

Please sign in to comment.