-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-112730: Make the test suite resilient to color-activation environment variables #117672
Conversation
pablogsal
commented
Apr 9, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Use color to highlight error locations #112730
…ronment variables
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
I am kind of sad that the solution is to add a special hack to suppress color to every test that would break. My ideal solution would be to suppress the color variables when |
That only takes half of the tests because that fixes the cases where the traceback is taken from a subprocess. The other half which is when the traceback is taken from the process that runs test itself you need the decorator because the test suite cannot be executed itself always with -E. To be honest I am happy to go this route (ignore on -E) but as @gpshead had some concerns with that I went with the most general solution first |
Got it. I wonder if |
That came up for termcolor and we replaced: return (
hasattr(sys.stdout, "isatty")
and sys.stdout.isatty()
and os.environ.get("TERM") != "dumb"
) With: # Then check system:
if os.environ.get("TERM") == "dumb":
return False
if not hasattr(sys.stdout, "fileno"):
return False
try:
return os.isatty(sys.stdout.fileno())
except io.UnsupportedOperation:
return sys.stdout.isatty() https://github.com/termcolor/termcolor/pull/56/files |
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.
So long as the number of decorator applications isn't huge I think this works. We should pay attention to users during the alpha and beta cycle. I'm assuming they aren't likely to find issues with this in CI and they probably do not enable colors there. It feels more likely to happen to an end user developer working within their local dev environment (which I believe is how we found it amongst ourselves?)
Lib/test/test_cmd_line_script.py
Outdated
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.
There's enough decorators in this test file I suggest just disabling it via setUpModule / tearDownModule instead.
FWIW I do not mind if we just wind up disabling it entirely on |
Ok, I will move to disable on |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This test is failing: FAIL: test_colorized_detection_checks_for_environment_variables (test.test_traceback.TestColorizedTraceback.test_colorized_detection_checks_for_environment_variables)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\test_traceback.py", line 4376, in test_colorized_detection_checks_for_environment_variables
self.assertEqual(traceback._can_colorize(), False)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: True != False Does it also need |
1526a99
to
4882250
Compare
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Hi. With this change, I am seeking several failures like the following one in ======================================================================
FAIL: test_env_var_invalid (test.test_tracemalloc.TestCommandLine.test_env_var_invalid) (nframe=-1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/..../pythonmain/cpython-main/Lib/test/test_tracemalloc.py", line 959, in test_env_var_invalid
self.check_env_var_invalid(nframe)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "/..../pythonmain/cpython-main/Lib/test/test_tracemalloc.py", line 953, in check_env_var_invalid
self.fail(f"unexpected output: {stderr!a}")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: unexpected output: b'ld.so.1: python: fatal: libpython3.13.so.1.0: open failed: No such file or directory\nld.so.1: python: fatal: relocation error: file /..../pythonmain/build/sparcv9/python: symbol Py_BytesMain: referenced symbol not found\n' It seems that because the environment is now being cleared in those tests, I am seeing this on Oracle Solaris, though atm I don't think this is specific to us? Also, I am executing the test suite in a pretty standard way:
|
I will look into this today! |
FWIW, I've seen failures in test_traceback/test_tracemalloc on a number of stable buildbots since this change. |