Skip to content

_colorize.can_colorize safety in test_argparse #135237

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

Open
tpburns opened this issue Jun 7, 2025 · 0 comments
Open

_colorize.can_colorize safety in test_argparse #135237

tpburns opened this issue Jun 7, 2025 · 0 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@tpburns
Copy link
Contributor

tpburns commented Jun 7, 2025

Bug report

Bug description:

In order to ensure its tests are meaningful even if color is disabled, the TestColorized test object in test_argparse modifies _colorize.can_colorize during setup, but does not subsequently restore it to the original value. As a consequence, the rest of the test session is polluted with colors/color codes even if NO_COLOR=1, or when in a dumb terminal or pipe. By comparison, we can look at the output of a similar setup in test_regrtest that uses mock.patch to only affect the state in that one test.

Given:

export NO_COLOR=1

Expected:

./python -m test test_regrtest -m TestColorized

Image

Polluted visuals:

./python -m test test_argparse test_regrtest -m TestColorized

Image

Polluted text:

./python -m test test_argparse test_regrtest -m TestColorized > OUTPUT.txt
less OUTPUT.txt

Image

CPython versions tested on:

CPython main branch, 3.14

Operating systems tested on:

Linux

Linked PRs

@tpburns tpburns added the type-bug An unexpected behavior, bug, or error label Jun 7, 2025
@picnixz picnixz added stdlib Python modules in the Lib dir tests Tests in the Lib/test dir and removed stdlib Python modules in the Lib dir labels Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy