Skip to content

Conversation

@pablogsal
Copy link
Member

@pablogsalpablogsal commented Apr 9, 2024

@hugovkhugovk changed the title gh-112730: Make the test suite relient to color-activation environment variablesgh-112730: Make the test suite resilient to color-activation environment variablesApr 9, 2024
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@gvanrossum
Copy link
Member

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 -E is used, or for the traceback code to be able to detect whether -E is used.

@pablogsal
Copy link
MemberAuthor

pablogsal commented Apr 9, 2024

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 -E is used, or for the traceback code to be able to detect whether -E is used.

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

@gvanrossum
Copy link
Member

Got it. I wonder if _can_colorize() is also a bit naive? Its default is to checking whether stderr is a tty, even when its caller is going to write to some other stream.

@hugovk
Copy link
Member

That came up for termcolor and we replaced:

return ( hasattr(sys.stdout, "isatty") andsys.stdout.isatty() andos.environ.get("TERM") !="dumb" )

With:

# Then check system:ifos.environ.get("TERM") =="dumb": returnFalseifnothasattr(sys.stdout, "fileno"): returnFalsetry: returnos.isatty(sys.stdout.fileno()) exceptio.UnsupportedOperation: returnsys.stdout.isatty()

https://github.com/termcolor/termcolor/pull/56/files

Copy link
Member

@gpsheadgpshead left a 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?)

Copy link
Member

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.

@gpshead
Copy link
Member

FWIW I do not mind if we just wind up disabling it entirely on -E, especially for the initial release of the feature. I agree that regardless of a PYTHON_ environment variable name prefix, it is a natural behavior change for people to look to -E and expect it to do.

@pablogsal
Copy link
MemberAuthor

Ok, I will move to disable on -E then and remove as many decorators as possible.

pablogsaland others added 3 commits April 10, 2024 11:19
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@hugovk
Copy link
Member

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_variablesself.assertEqual(traceback._can_colorize(), False) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: True != False

Does it also need @force_not_colorized?

@pablogsalpablogsalforce-pushed the no_colorize branch 2 times, most recently from 1526a99 to 4882250CompareApril 24, 2024 15:19
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
@pablogsalpablogsal merged commit 345e1e0 into python:mainApr 24, 2024
@pablogsalpablogsal deleted the no_colorize branch April 24, 2024 20:25
@hugovkhugovk mentioned this pull request Apr 25, 2024
@kulikjak
Copy link
Contributor

kulikjak commented Apr 25, 2024

Hi. With this change, I am seeking several failures like the following one in test_traceback and test_tracemalloc:

====================================================================== 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_invalidself.check_env_var_invalid(nframe) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^ File "/..../pythonmain/cpython-main/Lib/test/test_tracemalloc.py", line 953, in check_env_var_invalidself.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, LD_LIBRARY_PATH is no longer set in the subprocess, and libpython3.13.so.1.0 thus not found.

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:

cd /..../pythonmain/build/sparcv9; EXTRATESTOPTS="-v test_traceback test_tracemalloc" /usr/gnu/bin/make test

@pablogsal
Copy link
MemberAuthor

I will look into this today!

@ericsnowcurrently
Copy link
Member

FWIW, I've seen failures in test_traceback/test_tracemalloc on a number of stable buildbots since this change.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@pablogsal@gvanrossum@hugovk@gpshead@kulikjak@ericsnowcurrently