Skip to content
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

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Jan 9, 2025

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

  • You can disable colorizing for the whole class in setUpClass() instead of setUp().
  • Would not it be simpler to implement the core functionality as a generator-based context manager? You can use enterContext() or enterClassContext() with it.
  • You can use test.support.os_helper.EnvironmentVarGuard() to restore the environment and test.support.swap_attr() to restore _colorize.can_colorize.

You can also implement this as a mixin instead of patching a method (use a super() call in an overridden method). I do not say that it would be better, but it is just an alternative which you could have overlooked.

Lib/test/test_code_module.py Outdated Show resolved Hide resolved
@@ -17,6 +17,7 @@
import types
import unittest
import warnings
from collections.abc import Callable
Copy link
Contributor

Choose a reason for hiding this comment

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

This can go now :)

Suggested change
from collections.abc import Callable

@@ -17,6 +17,7 @@
import types
import unittest
import warnings
from collections.abc import Callable
Copy link
Member

Choose a reason for hiding this comment

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

The import is unused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review needs backport to 3.13 bugs and security fixes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants