Skip to content

Conversation

cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Oct 14, 2025

libregrtest redirects test output to a file as part of its operation. When unittest checks to see if it should colorize with isatty(sys.stdout) that returns False resulting in no colorizing of the unittest output.

Update libregrtest to set FORCE_COLOR=1 when redirecting test output so that unittest will do color printing.

libregrtest redirects test output to a file as part of its operation.
When `unittest` checks to see if it should colorize with
`isatty(sys.stdout)` that fails resulting in no colorizing of the
unittest output.

Update `libregrtest` to set `FORCE_COLOR=1` when redirecting test output
so that unittest will do color printing.
@cmaloney
Copy link
Contributor Author

I think this can be skip news as it's a strictly internal change / libregrtest isn't externally exposed

@vstinner
Copy link
Member

You might add a NEWS entry in the Tests category.

Co-authored-by: Victor Stinner <vstinner@python.org>
random.seed(runtests.random_seed)

if can_colorize(file=sys.stdout):
os.environ['FORCE_COLOR'] = "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not needed to get colors with ./python -m test -W -j0 (...) command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, -j0 results in multi-worker mode where this code isn't run, instead the worker.py code is used. This is only used in single process mode ex. ./python -m test -W --single-process

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants