Skip to content

Commit 80422ff

Browse files
committed
Fix tests when run with FORCE_COLOR=1
1 parent 41c3576 commit 80422ff

12 files changed

+93
-28
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
import weakref
2121
import operator
2222
from test import support
23-
from test.support import MISSING_C_DOCSTRINGS
24-
from test.support import import_helper
25-
from test.support import threading_helper
26-
from test.support import warnings_helper
27-
from test.support import requires_limited_api
28-
from test.support import expected_failure_if_gil_disabled
29-
from test.support import Py_GIL_DISABLED
23+
from test.support import (
24+
MISSING_C_DOCSTRINGS,
25+
Py_GIL_DISABLED,
26+
expected_failure_if_gil_disabled,
27+
force_not_colorized_test_class,
28+
import_helper,
29+
requires_limited_api,
30+
threading_helper,
31+
warnings_helper,
32+
)
3033
from test.support.script_helper import assert_python_failure, assert_python_ok, run_python_until_end
3134
try:
3235
import _posixsubprocess
@@ -73,6 +76,8 @@ class InstanceMethod:
7376
id = _testcapi.instancemethod(id)
7477
testfunction = _testcapi.instancemethod(testfunction)
7578

79+
80+
@force_not_colorized_test_class
7681
class CAPITest(unittest.TestCase):
7782

7883
def test_instancemethod(self):

Lib/test/test_cmd_line_script.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
import textwrap
1616
from test import support
17-
from test.support import import_helper, is_apple, os_helper
17+
from test.support import (
18+
force_not_colorized_test_class,
19+
import_helper,
20+
is_apple,
21+
os_helper,
22+
)
1823
from test.support.script_helper import (
1924
make_pkg, make_script, make_zip_pkg, make_zip_script,
2025
assert_python_ok, assert_python_failure, spawn_python, kill_python)
@@ -88,6 +93,8 @@ def _make_test_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,
8893
importlib.invalidate_caches()
8994
return to_return
9095

96+
97+
@force_not_colorized_test_class
9198
class CmdLineTest(unittest.TestCase):
9299
def _check_output(self, script_name, exit_code, data,
93100
expected_file, expected_argv0,

Lib/test/test_compileall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
_have_multiprocessing = False
2727

2828
from test import support
29+
from test.support import force_not_colorized
2930
from test.support import os_helper
3031
from test.support import script_helper
3132
from test.test_py_compile import without_source_date_epoch
@@ -766,6 +767,7 @@ def test_d_compile_error(self):
766767
rc, out, err = self.assertRunNotOK('-q', '-d', 'dinsdale', self.pkgdir)
767768
self.assertRegex(out, b'File "dinsdale')
768769

770+
@force_not_colorized
769771
def test_d_runtime_error(self):
770772
bazfn = script_helper.make_script(self.pkgdir, 'baz', 'raise Exception')
771773
self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir)

Lib/test/test_eof.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
from codecs import BOM_UTF8
5-
from test import support
5+
from test.support import force_not_colorized
66
from test.support import os_helper
77
from test.support import script_helper
88
from test.support import warnings_helper
@@ -44,6 +44,7 @@ def test_EOFS(self):
4444
self.assertEqual(cm.exception.text, "ä = '''thîs is ")
4545
self.assertEqual(cm.exception.offset, 5)
4646

47+
@force_not_colorized
4748
def test_EOFS_with_file(self):
4849
expect = ("(<string>, line 1)")
4950
with os_helper.temp_dir() as temp_dir:
@@ -123,6 +124,7 @@ def test_line_continuation_EOF(self):
123124
self.assertEqual(str(cm.exception), expect)
124125

125126
@unittest.skipIf(not sys.executable, "sys.executable required")
127+
@force_not_colorized
126128
def test_line_continuation_EOF_from_file_bpo2180(self):
127129
"""Ensure tok_nextc() does not add too many ending newlines."""
128130
with os_helper.temp_dir() as temp_dir:

Lib/test/test_exceptions.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
from itertools import product
1212
from textwrap import dedent
1313

14-
from test.support import (captured_stderr, check_impl_detail,
15-
cpython_only, gc_collect,
16-
no_tracing, script_helper,
17-
SuppressCrashReport,
18-
force_not_colorized)
14+
from test.support import (
15+
SuppressCrashReport,
16+
captured_stderr,
17+
check_impl_detail,
18+
cpython_only,
19+
force_not_colorized,
20+
force_not_colorized_test_class,
21+
gc_collect,
22+
no_tracing,
23+
script_helper,
24+
)
1925
from test.support.import_helper import import_module
2026
from test.support.os_helper import TESTFN, unlink
2127
from test.support.warnings_helper import check_warnings
@@ -1465,6 +1471,7 @@ def gen():
14651471

14661472
@cpython_only
14671473
@unittest.skipIf(_testcapi is None, "requires _testcapi")
1474+
@force_not_colorized
14681475
def test_recursion_normalizing_infinite_exception(self):
14691476
# Issue #30697. Test that a RecursionError is raised when
14701477
# maximum recursion depth has been exceeded when creating
@@ -2180,6 +2187,7 @@ def test_multiline_not_highlighted(self):
21802187
self.assertEqual(result[-len(expected):], expected)
21812188

21822189

2190+
@force_not_colorized_test_class
21832191
class SyntaxErrorTests(unittest.TestCase):
21842192
maxDiff = None
21852193

Lib/test/test_import/__init__.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,30 @@
2727
from unittest import mock
2828
import _imp
2929

30-
from test.support import os_helper
3130
from test.support import (
32-
STDLIB_DIR, swap_attr, swap_item, cpython_only, is_apple_mobile, is_emscripten,
33-
is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS,
34-
requires_gil_enabled, Py_GIL_DISABLED, no_rerun)
31+
STDLIB_DIR,
32+
Py_GIL_DISABLED,
33+
Py_TRACE_REFS,
34+
cpython_only,
35+
force_not_colorized_test_class,
36+
is_apple_mobile,
37+
is_emscripten,
38+
is_wasi,
39+
no_rerun,
40+
os_helper,
41+
requires_gil_enabled,
42+
run_in_subinterp,
43+
run_in_subinterp_with_config,
44+
script_helper,
45+
swap_attr,
46+
swap_item,
47+
threading_helper,
48+
)
3549
from test.support.import_helper import (
3650
forget, make_legacy_pyc, unlink, unload, ready_to_import,
3751
DirsOnSysPath, CleanImport, import_module)
3852
from test.support.os_helper import (
3953
TESTFN, rmtree, temp_umask, TESTFN_UNENCODABLE)
40-
from test.support import script_helper
41-
from test.support import threading_helper
4254
from test.test_importlib.util import uncache
4355
from types import ModuleType
4456
try:
@@ -333,6 +345,7 @@ def _from_subinterp(cls, name, interpid, pipe, script_kwargs):
333345
return cls.parse(text.decode())
334346

335347

348+
@force_not_colorized_test_class
336349
class ImportTests(unittest.TestCase):
337350

338351
def setUp(self):

Lib/test/test_inspect/test_inspect.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@
3535
except ImportError:
3636
ThreadPoolExecutor = None
3737

38-
from test.support import cpython_only, import_helper
39-
from test.support import MISSING_C_DOCSTRINGS, ALWAYS_EQ
38+
from test.support import (
39+
ALWAYS_EQ,
40+
MISSING_C_DOCSTRINGS,
41+
cpython_only,
42+
force_not_colorized,
43+
has_subprocess_support,
44+
import_helper,
45+
)
4046
from test.support.import_helper import DirsOnSysPath, ready_to_import
4147
from test.support.os_helper import TESTFN, temp_cwd
4248
from test.support.script_helper import assert_python_ok, assert_python_failure, kill_python
43-
from test.support import has_subprocess_support
4449
from test import support
4550

4651
from test.test_inspect import inspect_fodder as mod
@@ -890,6 +895,7 @@ def test_getsource_stdlib_decimal(self):
890895
self.assertEqual(src.splitlines(True), lines)
891896

892897
class TestGetsourceInteractive(unittest.TestCase):
898+
@force_not_colorized
893899
def test_getclasses_interactive(self):
894900
# bpo-44648: simulate a REPL session;
895901
# there is no `__file__` in the __main__ module

Lib/test/test_regrtest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from xml.etree import ElementTree
2727

2828
from test import support
29+
from test.support import force_not_colorized_test_class
2930
from test.support import import_helper
3031
from test.support import os_helper
3132
from test.libregrtest import cmdline
@@ -792,6 +793,7 @@ def test_finds_expected_number_of_tests(self):
792793
f'{", ".join(output.splitlines())}')
793794

794795

796+
@force_not_colorized_test_class
795797
class ProgramsTestCase(BaseTestCase):
796798
"""
797799
Test various ways to run the Python test suite. Use options close
@@ -905,6 +907,7 @@ def test_pcbuild_rt(self):
905907
self.run_batch(script, *rt_args, *self.regrtest_args, *self.tests)
906908

907909

910+
@force_not_colorized_test_class
908911
class ArgsTestCase(BaseTestCase):
909912
"""
910913
Test arguments of the Python test suite.

Lib/test/test_repl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from test import support
1010
from test.support import (
1111
cpython_only,
12+
force_not_colorized_test_class,
1213
has_subprocess_support,
1314
os_helper,
1415
SuppressCrashReport,
@@ -70,6 +71,7 @@ def run_on_interactive_mode(source):
7071
return output
7172

7273

74+
@force_not_colorized_test_class
7375
class TestInteractiveInterpreter(unittest.TestCase):
7476

7577
@cpython_only
@@ -273,6 +275,8 @@ def test_asyncio_repl_is_ok(self):
273275

274276
self.assertEqual(exit_code, 0, "".join(output))
275277

278+
279+
@force_not_colorized_test_class
276280
class TestInteractiveModeSyntaxErrors(unittest.TestCase):
277281

278282
def test_interactive_syntax_error_correct_line(self):

Lib/test/test_runpy.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
import textwrap
1313
import unittest
1414
import warnings
15-
from test.support import (infinite_recursion, no_tracing, verbose,
16-
requires_subprocess, requires_resource)
15+
from test.support import (
16+
force_not_colorized_test_class,
17+
infinite_recursion,
18+
no_tracing,
19+
requires_resource,
20+
requires_subprocess,
21+
verbose,
22+
)
1723
from test.support.import_helper import forget, make_legacy_pyc, unload
1824
from test.support.os_helper import create_empty_file, temp_dir, FakePath
1925
from test.support.script_helper import make_script, make_zip_script
@@ -758,6 +764,7 @@ def test_encoding(self):
758764
self.assertEqual(result['s'], "non-ASCII: h\xe9")
759765

760766

767+
@force_not_colorized_test_class
761768
class TestExit(unittest.TestCase):
762769
STATUS_CONTROL_C_EXIT = 0xC000013A
763770
EXPECTED_CODE = (

Lib/test/test_tracemalloc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ def check_sys_xoptions_invalid(self, nframe):
981981
return
982982
self.fail(f"unexpected output: {stderr!a}")
983983

984+
@force_not_colorized
984985
def test_sys_xoptions_invalid(self):
985986
for nframe in INVALID_NFRAME:
986987
with self.subTest(nframe=nframe):

Lib/test/test_unicodedata.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
"""
88

99
import hashlib
10-
from http.client import HTTPException
1110
import sys
1211
import unicodedata
1312
import unittest
14-
from test.support import (open_urlresource, requires_resource, script_helper,
15-
cpython_only, check_disallow_instantiation)
13+
from http.client import HTTPException
14+
from test.support import (
15+
check_disallow_instantiation,
16+
cpython_only,
17+
force_not_colorized,
18+
open_urlresource,
19+
requires_resource,
20+
script_helper,
21+
)
1622

1723

1824
class UnicodeMethodsTest(unittest.TestCase):
@@ -277,6 +283,7 @@ def test_disallow_instantiation(self):
277283
# Ensure that the type disallows instantiation (bpo-43916)
278284
check_disallow_instantiation(self, unicodedata.UCD)
279285

286+
@force_not_colorized
280287
def test_failed_import_during_compiling(self):
281288
# Issue 4367
282289
# Decoding \N escapes requires the unicodedata module. If it can't be

0 commit comments

Comments
 (0)