Skip to content

Commit 4067c9b

Browse files
Replace NO_COLOR=1 trick with @force_not_colorized* helpers
1 parent 9b637d1 commit 4067c9b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Lib/test/test_compiler_assemble.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import dis
22
import io
3-
import os
43
import textwrap
54
import types
65

76
from test.support.bytecode_helper import AssemblerTestCase
8-
9-
10-
os.environ.setdefault("NO_COLOR", "1")
7+
from test.support import force_not_colorized
118

129
# Tests for the code-object creation stage of the compiler.
1310

@@ -118,6 +115,7 @@ def inner():
118115
self.assemble_test(instructions, metadata, expected)
119116

120117

118+
@force_not_colorized
121119
def test_exception_table(self):
122120
metadata = {
123121
'filename' : 'exc.py',

Lib/test/test_dis.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77
import io
88
import itertools
99
import opcode
10-
import os
1110
import re
1211
import sys
1312
import tempfile
1413
import textwrap
1514
import types
1615
import unittest
17-
from test.support import (captured_stdout, requires_debug_ranges,
18-
requires_specialization, cpython_only,
19-
os_helper, import_helper, reset_code)
16+
from test.support import (captured_stdout, force_not_colorized_test_class,
17+
requires_debug_ranges, requires_specialization,
18+
cpython_only, os_helper, import_helper, reset_code)
2019
from test.support.bytecode_helper import BytecodeTestCase
2120

2221

23-
os.environ.setdefault("NO_COLOR", "1")
24-
2522
CACHE = dis.opmap["CACHE"]
2623

2724
def get_tb():
@@ -995,6 +992,7 @@ def do_disassembly_compare(self, got, expected):
995992
self.assertEqual(got, expected)
996993

997994

995+
@force_not_colorized_test_class
998996
class DisTests(DisTestBase):
999997

1000998
maxDiff = None
@@ -1471,6 +1469,7 @@ def f():
14711469
self.assertEqual(assem_op, assem_cache)
14721470

14731471

1472+
@force_not_colorized_test_class
14741473
class DisWithFileTests(DisTests):
14751474

14761475
# Run the tests again, using the file arg instead of print
@@ -1993,6 +1992,7 @@ def assertInstructionsEqual(self, instrs_1, instrs_2, /):
19931992
instrs_2 = [instr_2._replace(positions=None, cache_info=None) for instr_2 in instrs_2]
19941993
self.assertEqual(instrs_1, instrs_2)
19951994

1995+
@force_not_colorized_test_class
19961996
class InstructionTests(InstructionTestCase):
19971997

19981998
def __init__(self, *args):
@@ -2314,6 +2314,7 @@ def test_cache_offset_and_end_offset(self):
23142314

23152315
# get_instructions has its own tests above, so can rely on it to validate
23162316
# the object oriented API
2317+
@force_not_colorized_test_class
23172318
class BytecodeTests(InstructionTestCase, DisTestBase):
23182319

23192320
def test_instantiation(self):
@@ -2445,6 +2446,7 @@ def func():
24452446
self.assertEqual(offsets, [0, 2])
24462447

24472448

2449+
@force_not_colorized_test_class
24482450
class TestDisTraceback(DisTestBase):
24492451
def setUp(self) -> None:
24502452
try: # We need to clean up existing tracebacks
@@ -2482,6 +2484,7 @@ def test_distb_explicit_arg(self):
24822484
self.do_disassembly_compare(self.get_disassembly(tb), dis_traceback)
24832485

24842486

2487+
@force_not_colorized_test_class
24852488
class TestDisTracebackWithFile(TestDisTraceback):
24862489
# Run the `distb` tests again, using the file arg instead of print
24872490
def get_disassembly(self, tb):
@@ -2516,6 +2519,7 @@ def _unroll_caches_as_Instructions(instrs, show_caches=False):
25162519
False, None, None, instr.positions)
25172520

25182521

2522+
@force_not_colorized_test_class
25192523
class TestDisCLI(unittest.TestCase):
25202524

25212525
def setUp(self):

0 commit comments

Comments
 (0)