Skip to content

Commit

Permalink
Fix tests when NO_COLOR is set in the calling environment
Browse files Browse the repository at this point in the history
Add `FORCE_COLOR` and `NO_COLOR` variables to the `isolate()` fixture
to ensure that these two variables do not affect internal test output.
This fixes the following two test failures when pytest is called with
`NO_COLOR` set:

```
FAILED tests/unit/test_exceptions.py::TestDiagnosticPipErrorPresentation_ASCII::test_complete_color - AssertionError: assert '\x1b[1merror...ing harder.\n' == '\x1b[1;31mer...ing harder.\n'
FAILED tests/unit/test_exceptions.py::TestDiagnosticPipErrorPresentation_Unicode::test_complete_color - AssertionError: assert '\x1b[1merror...ing harder.\n' == '\x1b[1;31mer...ing harder.\n'
```
  • Loading branch information
mgorny committed Nov 25, 2023
1 parent 2a0acb5 commit ad01e9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Empty file.
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ def isolate(tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> None:
# Make sure tests don't share a requirements tracker.
monkeypatch.delenv("PIP_BUILD_TRACKER", False)

# Make sure color control variables don't affect internal output.
monkeypatch.delenv("FORCE_COLOR", False)
monkeypatch.delenv("NO_COLOR", False)

# FIXME: Windows...
os.makedirs(os.path.join(home_dir, ".config", "git"))
with open(os.path.join(home_dir, ".config", "git", "config"), "wb") as fp:
Expand Down

0 comments on commit ad01e9c

Please sign in to comment.