Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

_colorize.can_colorize safety in test_argparse #135237

Copy link
Copy link
@tpburns

Description

@tpburns
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    Status
    Doc issues
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.