GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-112730: Make the test suite resilient to color-activation environment variables by pablogsal · Pull Request #117672 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Apr 9, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Use color to highlight error locations #112730

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pablogsal
pythongh-112730: Make the test suite relient to color-activation envi…
e08e26c
…ronment variables
@pablogsal
pablogsal requested review from ericsnowcurrently, gvanrossum, iritkatriel, markshannon and terryjreedy as code owners April 9, 2024 10:13
@bedevere-app bedevere-app Bot mentioned this pull request Apr 9, 2024
Use color to highlight error locations #112730
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 9, 2024
@pablogsal
Force color in CI
ee00903
@pablogsal
pablogsal requested review from ezio-melotti and hugovk as code owners April 9, 2024 10:16
@pablogsal pablogsal added the skip news label Apr 9, 2024
hugovk
hugovk reviewed Apr 9, 2024
View reviewed changes
Comment thread .github/workflows/reusable-ubuntu.yml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/support/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/support/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hugovk hugovk changed the title gh-112730: Make the test suite relient to color-activation environment variables gh-112730: Make the test suite resilient to color-activation environment variables Apr 9, 2024
hugovk
hugovk reviewed Apr 9, 2024
View reviewed changes
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal @hugovk
Apply suggestions from code review
081aaed
Co-authored-by: Hugo van Kemenade <[email protected]>
@gvanrossum

gvanrossum commented Apr 9, 2024

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Apr 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Apr 9, 2024

Copy link
Copy Markdown
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.

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Apr 9, 2024

Copy link
Copy Markdown
Member

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

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk
hugovk reviewed Apr 9, 2024
View reviewed changes
Comment thread Lib/test/support/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

gpshead
gpshead reviewed Apr 10, 2024
View reviewed changes

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

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?)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_cmd_line_script.py

@gpshead gpshead Apr 10, 2024

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gpshead

gpshead commented Apr 10, 2024

Copy link
Copy Markdown
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.

gvanrossum reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Apr 10, 2024

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal and others added 3 commits April 10, 2024 11:19
@pablogsal @hugovk
Update Lib/test/support/__init__.py
ee4966a
Co-authored-by: Hugo van Kemenade <[email protected]>
@pablogsal
Deactivate on -E
15c840a
@pablogsal
Implement extra checks in can_colorize
73a4fb1
@hugovk hugovk mentioned this pull request Apr 10, 2024
gh-117225: Add color to doctest output #117583
Merged
@hugovk

hugovk commented Apr 14, 2024

Copy link
Copy Markdown
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_variables
    self.assertEqual(traceback._can_colorize(), False)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: True != False

Does it also need @force_not_colorized?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
Merge remote-tracking branch 'upstream/main' into no_colorize
3e28b76
@pablogsal
pablogsal force-pushed the no_colorize branch 2 times, most recently from 1526a99 to 4882250 Compare April 24, 2024 15:19
@pablogsal
fixup! Merge remote-tracking branch 'upstream/main' into no_colorize
dca3366
Signed-off-by: Pablo Galindo <[email protected]>
@pablogsal
pablogsal force-pushed the no_colorize branch from 4882250 to dca3366 Compare April 24, 2024 17:17
@pablogsal
pablogsal merged commit 345e1e0 into python:main Apr 24, 2024
@pablogsal
pablogsal deleted the no_colorize branch April 24, 2024 20:25
@bedevere-app bedevere-app Bot removed the awaiting core review label Apr 24, 2024
@hugovk hugovk mentioned this pull request Apr 25, 2024
Refresh doctest summary #117225
Closed
@kulikjak

kulikjak commented Apr 25, 2024 •
edited by hugovk
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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_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, 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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk hugovk mentioned this pull request Apr 25, 2024
JIT CI is broken due to test_traceback & test_tracemalloc #118275
Closed
@pablogsal

pablogsal commented Apr 25, 2024

Copy link
Copy Markdown
Member Author

I will look into this today!

kulikjak and nineteendo reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ericsnowcurrently

ericsnowcurrently commented Apr 25, 2024

Copy link
Copy Markdown
Member

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

pablogsal reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@gpshead gpshead gpshead left review comments
@hugovk hugovk hugovk left review comments
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@terryjreedy terryjreedy Awaiting requested review from terryjreedy terryjreedy is a code owner
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner
@markshannon markshannon Awaiting requested review from markshannon
@gvanrossum gvanrossum Awaiting requested review from gvanrossum
@ezio-melotti ezio-melotti Awaiting requested review from ezio-melotti ezio-melotti is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@pablogsal @gvanrossum @hugovk @gpshead @kulikjak @ericsnowcurrently
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.