Title: _colorize.can_colorize safety in test_argparse · Issue #135237 · python/cpython · GitHub
Open Graph Title: _colorize.can_colorize safety in test_argparse · Issue #135237 · python/cpython
X Title: _colorize.can_colorize safety in test_argparse · Issue #135237 · python/cpython
Description: 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 o...
Open Graph Description: 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 d...
X Description: 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 d...
Opengraph URL: https://github.com/python/cpython/issues/135237
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_colorize.can_colorize safety in test_argparse","articleBody":"# Bug report\n\n### Bug description:\n\nIn 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.\n\nGiven:\n```\nexport NO_COLOR=1\n```\n\nExpected:\n```\n./python -m test test_regrtest -m TestColorized\n```\n\n\n\nPolluted visuals:\n```\n./python -m test test_argparse test_regrtest -m TestColorized\n```\n\n\n\nPolluted text:\n```\n./python -m test test_argparse test_regrtest -m TestColorized \u003e OUTPUT.txt\nless OUTPUT.txt\n```\n\n\n\n### CPython versions tested on:\n\nCPython main branch, 3.14\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-135238\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/tpburns","@type":"Person","name":"tpburns"},"datePublished":"2025-06-07T16:50:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/135237/cpython/issues/135237"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3bcfea74-0fa8-d6bb-b328-659fd02fa9e1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98B6:10D0A2:25952:31F0D:696F29FF |
| html-safe-nonce | a6cbefdc4b47b103f11d69d895df48c620ecfc1e21adcf30f8d2e96e87b96f43 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEI2OjEwRDBBMjoyNTk1MjozMUYwRDo2OTZGMjlGRiIsInZpc2l0b3JfaWQiOiI2Njk1ODk0NTY0MDQ1ODc1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aab212c68e6293d72aeba0554432d8aadffed6a6d55c929a332127f09752125d |
| hovercard-subject-tag | issue:3127252927 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/135237/issue_layout |
| twitter:image | https://opengraph.githubassets.com/775c87993eed11602469726afe0e1745e705dee15440b62bb9f8d25f4cfa3a2d/python/cpython/issues/135237 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/775c87993eed11602469726afe0e1745e705dee15440b62bb9f8d25f4cfa3a2d/python/cpython/issues/135237 |
| og:image:alt | 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 d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tpburns |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width