gh-127873: Only check sys.flags.ignore_environment
for PYTHON*
env vars
#127877
+183
−90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
-E
is passed (and thereforesys.flags.ignore_environment
is true), we should only ignore only env vars matchingPYTHON*
; in this case, onlyPYTHON_COLORS
.We should not ignore the other env vars:
FORCE_COLOR
/NO_COLOR
/TERM
.Re: https://docs.python.org/3/using/cmdline.html#cmdoption-E
Fixing this revealed some tests that failed because of inserted colour codes. For example, in "ZeroDivisionError: division by zero", the parts "ZeroDivisionError", ":" and "division by zero" are all different colours.
For these test cases, I wrapped then with the
@force_not_colorized
decorator, or, where there were a number of them, I wrapped the test class in the newforce_not_colorized_test_class
decorator. This was a suggestion from #127223 (comment). And from that PR, I replaced some of the numerous function decorators with the class decorator.can_colorize()
ignoresFORCE_COLOR
/NO_COLOR
/TERM
when-E
is set #127873