Skip to content

gh-128595: Add test class helper to force no terminal colour #128687

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

Merged
merged 10 commits into from
Jan 13, 2025
Prev Previous commit
Next Next commit
Use setUpClass/tearDownClass instead of setUp/tearDown
  • Loading branch information
hugovk committed Jan 10, 2025
commit e9aa442e13aa5fc13219ce963380c3866911ae06
40 changes: 23 additions & 17 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2870,24 +2870,30 @@ def wrapper(*args, **kwargs):
_re_enable_terminal_color(original_fn, variables)
return wrapper

def force_not_colorized_test_class(cls):
"""Force the terminal not to be colorized."""
original_setup = cls.setUp
original_teardown = cls.tearDown

@functools.wraps(cls.setUp)
def setUp_wrapper(self, *args, **kwargs):
self._original_fn, self._variables = _disable_terminal_color()

return original_setup(self, *args, **kwargs)

@functools.wraps(cls.tearDown)
def tearDown_wrapper(self, *args, **kwargs):
_re_enable_terminal_color(self._original_fn, self._variables)
return original_teardown(self, *args, **kwargs)

cls.setUp = setUp_wrapper
cls.tearDown = tearDown_wrapper
def force_not_colorized_test_class(cls):
"""Force the terminal not to be colorized for the entire test class."""
original_setUpClass = cls.setUpClass
original_tearDownClass = cls.tearDownClass

@classmethod
@functools.wraps(cls.setUpClass)
def new_setUpClass(cls):
original_fn, variables = _disable_terminal_color()
cls._original_fn = original_fn
cls._variables = variables
if original_setUpClass:
original_setUpClass()

@classmethod
@functools.wraps(cls.tearDownClass)
def new_tearDownClass(cls):
if original_tearDownClass:
original_tearDownClass()
_re_enable_terminal_color(cls._original_fn, cls._variables)

cls.setUpClass = new_setUpClass
cls.tearDownClass = new_tearDownClass
return cls


Expand Down
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