-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tests when NO_COLOR is set in the calling environment #12415
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! This is something I was going to suggest at some point.
To make this change truly tested in pip's own CI, how about including a commit reverting 1b33f4b?
(context comment) I recently discovered that there are bugs related with As of today, using both |
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' ```
This reverts commit 1b33f4b. Now the test suite strips `FORCE_COLOR` internally, so it should be fine to run with colors enabled for nox.
I'm sorry about forgetting about this pull request. I've added the revert now and rebased. |
Ok, so the problem with The options I can think of are:
|
(1) sounds reasonable, if you ask me. |
Lower the scope of `simple_script` fixture used in `test_inspect` from `session` to (implicit) `function`, to make it match the `isolate` fixture and therefore make the fixture run in isolation. Per the documentation [1], pytest initializes higher-scope fixtures first, and lower-scope fixtures cannot be used in them. Since within the same scope, autouse fixtures are always loaded before regular fixtures, no further adjustment is necessary. This should have no ill side effects, as the fixture is used by a single test only. [1] https://docs.pytest.org/en/stable/reference/fixtures.html#fixture-instantiation-order
Ok, I think it's good now. |
@pradyunsg I think this should be mergeable |
Thank you! |
Add
FORCE_COLOR
andNO_COLOR
variables to theisolate()
fixture to ensure that these two variables do not affect internal test output. This fixes the following two test failures when pytest is called withNO_COLOR
set: