Skip to content

Commit 41c3576

Browse files
committed
Replace force_not_colorized with force_not_colorized_test_class
1 parent adae1cb commit 41c3576

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

Lib/test/test_unittest/test_program.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
from test import support
55
import unittest
66
import test.test_unittest
7-
from test.support import force_not_colorized
7+
from test.support import force_not_colorized_test_class
88
from test.test_unittest.test_result import BufferedWriter
99

1010

11+
@force_not_colorized_test_class
1112
class Test_TestProgram(unittest.TestCase):
1213

1314
def test_discovery_from_dotted_path(self):
@@ -121,7 +122,6 @@ def run(self, test):
121122
self.assertEqual(['test.test_unittest', 'test.test_unittest2'],
122123
program.testNames)
123124

124-
@force_not_colorized
125125
def test_NonExit(self):
126126
stream = BufferedWriter()
127127
program = unittest.main(exit=False,
@@ -137,7 +137,6 @@ def test_NonExit(self):
137137
'expected failures=1, unexpected successes=1)\n')
138138
self.assertTrue(out.endswith(expected))
139139

140-
@force_not_colorized
141140
def test_Exit(self):
142141
stream = BufferedWriter()
143142
with self.assertRaises(SystemExit) as cm:
@@ -155,7 +154,6 @@ def test_Exit(self):
155154
'expected failures=1, unexpected successes=1)\n')
156155
self.assertTrue(out.endswith(expected))
157156

158-
@force_not_colorized
159157
def test_ExitAsDefault(self):
160158
stream = BufferedWriter()
161159
with self.assertRaises(SystemExit):
@@ -171,7 +169,6 @@ def test_ExitAsDefault(self):
171169
'expected failures=1, unexpected successes=1)\n')
172170
self.assertTrue(out.endswith(expected))
173171

174-
@force_not_colorized
175172
def test_ExitSkippedSuite(self):
176173
stream = BufferedWriter()
177174
with self.assertRaises(SystemExit) as cm:
@@ -184,7 +181,6 @@ def test_ExitSkippedSuite(self):
184181
expected = '\n\nOK (skipped=1)\n'
185182
self.assertTrue(out.endswith(expected))
186183

187-
@force_not_colorized
188184
def test_ExitEmptySuite(self):
189185
stream = BufferedWriter()
190186
with self.assertRaises(SystemExit) as cm:

Lib/test/test_unittest/test_result.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import unittest
66
from test.support import (
77
captured_stdout,
8-
force_not_colorized,
98
force_not_colorized_test_class,
109
warnings_helper,
1110
)
@@ -37,6 +36,7 @@ def bad_cleanup2():
3736
raise ValueError('bad cleanup2')
3837

3938

39+
@force_not_colorized_test_class
4040
class Test_TestResult(unittest.TestCase):
4141
# Note: there are not separate tests for TestResult.wasSuccessful(),
4242
# TestResult.errors, TestResult.failures, TestResult.testsRun or
@@ -208,7 +208,6 @@ def test_1(self):
208208
self.assertIs(test_case, test)
209209
self.assertIsInstance(formatted_exc, str)
210210

211-
@force_not_colorized
212211
def test_addFailure_filter_traceback_frames(self):
213212
class Foo(unittest.TestCase):
214213
def test_1(self):
@@ -235,7 +234,6 @@ def get_exc_info():
235234
self.assertEqual(len(dropped), 1)
236235
self.assertIn("raise self.failureException(msg)", dropped[0])
237236

238-
@force_not_colorized
239237
def test_addFailure_filter_traceback_frames_context(self):
240238
class Foo(unittest.TestCase):
241239
def test_1(self):
@@ -265,7 +263,6 @@ def get_exc_info():
265263
self.assertEqual(len(dropped), 1)
266264
self.assertIn("raise self.failureException(msg)", dropped[0])
267265

268-
@force_not_colorized
269266
def test_addFailure_filter_traceback_frames_chained_exception_self_loop(self):
270267
class Foo(unittest.TestCase):
271268
def test_1(self):
@@ -291,7 +288,6 @@ def get_exc_info():
291288
formatted_exc = result.failures[0][1]
292289
self.assertEqual(formatted_exc.count("Exception: Loop\n"), 1)
293290

294-
@force_not_colorized
295291
def test_addFailure_filter_traceback_frames_chained_exception_cycle(self):
296292
class Foo(unittest.TestCase):
297293
def test_1(self):
@@ -453,7 +449,6 @@ def testFailFast(self):
453449
result.addUnexpectedSuccess(None)
454450
self.assertTrue(result.shouldStop)
455451

456-
@force_not_colorized
457452
def testFailFastSetByRunner(self):
458453
stream = BufferedWriter()
459454
runner = unittest.TextTestRunner(stream=stream, failfast=True)
@@ -465,6 +460,7 @@ def test(result):
465460
self.assertTrue(stream.getvalue().endswith('\n\nOK\n'))
466461

467462

463+
@force_not_colorized_test_class
468464
class Test_TextTestResult(unittest.TestCase):
469465
maxDiff = None
470466

@@ -627,7 +623,6 @@ def _run_test(self, test_name, verbosity, tearDownError=None):
627623
test.run(result)
628624
return stream.getvalue()
629625

630-
@force_not_colorized
631626
def testDotsOutput(self):
632627
self.assertEqual(self._run_test('testSuccess', 1), '.')
633628
self.assertEqual(self._run_test('testSkip', 1), 's')
@@ -636,7 +631,6 @@ def testDotsOutput(self):
636631
self.assertEqual(self._run_test('testExpectedFailure', 1), 'x')
637632
self.assertEqual(self._run_test('testUnexpectedSuccess', 1), 'u')
638633

639-
@force_not_colorized
640634
def testLongOutput(self):
641635
classname = f'{__name__}.{self.Test.__qualname__}'
642636
self.assertEqual(self._run_test('testSuccess', 2),
@@ -652,21 +646,17 @@ def testLongOutput(self):
652646
self.assertEqual(self._run_test('testUnexpectedSuccess', 2),
653647
f'testUnexpectedSuccess ({classname}.testUnexpectedSuccess) ... unexpected success\n')
654648

655-
@force_not_colorized
656649
def testDotsOutputSubTestSuccess(self):
657650
self.assertEqual(self._run_test('testSubTestSuccess', 1), '.')
658651

659-
@force_not_colorized
660652
def testLongOutputSubTestSuccess(self):
661653
classname = f'{__name__}.{self.Test.__qualname__}'
662654
self.assertEqual(self._run_test('testSubTestSuccess', 2),
663655
f'testSubTestSuccess ({classname}.testSubTestSuccess) ... ok\n')
664656

665-
@force_not_colorized
666657
def testDotsOutputSubTestMixed(self):
667658
self.assertEqual(self._run_test('testSubTestMixed', 1), 'sFE')
668659

669-
@force_not_colorized
670660
def testLongOutputSubTestMixed(self):
671661
classname = f'{__name__}.{self.Test.__qualname__}'
672662
self.assertEqual(self._run_test('testSubTestMixed', 2),
@@ -675,7 +665,6 @@ def testLongOutputSubTestMixed(self):
675665
f' testSubTestMixed ({classname}.testSubTestMixed) [fail] (c=3) ... FAIL\n'
676666
f' testSubTestMixed ({classname}.testSubTestMixed) [error] (d=4) ... ERROR\n')
677667

678-
@force_not_colorized
679668
def testDotsOutputTearDownFail(self):
680669
out = self._run_test('testSuccess', 1, AssertionError('fail'))
681670
self.assertEqual(out, 'F')
@@ -686,7 +675,6 @@ def testDotsOutputTearDownFail(self):
686675
out = self._run_test('testSkip', 1, AssertionError('fail'))
687676
self.assertEqual(out, 'sF')
688677

689-
@force_not_colorized
690678
def testLongOutputTearDownFail(self):
691679
classname = f'{__name__}.{self.Test.__qualname__}'
692680
out = self._run_test('testSuccess', 2, AssertionError('fail'))

Lib/test/test_unittest/test_runner.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import io
22
import os
3-
import sys
43
import pickle
54
import subprocess
6-
from test import support
7-
from test.support import force_not_colorized
8-
5+
import sys
96
import unittest
10-
from unittest.case import _Outcome
11-
7+
from test import support
8+
from test.support import force_not_colorized, force_not_colorized_test_class
129
from test.test_unittest.support import (
1310
BufferedWriter,
1411
LoggingResult,
1512
ResultWithNoStartTestRunStopTestRun,
1613
)
14+
from unittest.case import _Outcome
1715

1816

1917
def resultFactory(*_):
@@ -251,6 +249,7 @@ def testNothing(self):
251249
self.assertEqual(test._cleanups, [])
252250

253251

252+
@force_not_colorized_test_class
254253
class TestClassCleanup(unittest.TestCase):
255254
def test_addClassCleanUp(self):
256255
class TestableTest(unittest.TestCase):
@@ -418,7 +417,6 @@ def cleanup2():
418417
self.assertIsInstance(e2[1], CustomError)
419418
self.assertEqual(str(e2[1]), 'cleanup1')
420419

421-
@force_not_colorized
422420
def test_with_errors_addCleanUp(self):
423421
ordering = []
424422
class TestableTest(unittest.TestCase):
@@ -442,7 +440,6 @@ def tearDownClass(cls):
442440
['setUpClass', 'setUp', 'cleanup_exc',
443441
'tearDownClass', 'cleanup_good'])
444442

445-
@force_not_colorized
446443
def test_run_with_errors_addClassCleanUp(self):
447444
ordering = []
448445
class TestableTest(unittest.TestCase):
@@ -466,7 +463,6 @@ def tearDownClass(cls):
466463
['setUpClass', 'setUp', 'test', 'cleanup_good',
467464
'tearDownClass', 'cleanup_exc'])
468465

469-
@force_not_colorized
470466
def test_with_errors_in_addClassCleanup_and_setUps(self):
471467
ordering = []
472468
class_blow_up = False
@@ -519,7 +515,6 @@ def tearDownClass(cls):
519515
['setUpClass', 'setUp', 'tearDownClass',
520516
'cleanup_exc'])
521517

522-
@force_not_colorized
523518
def test_with_errors_in_tearDownClass(self):
524519
ordering = []
525520
class TestableTest(unittest.TestCase):
@@ -596,7 +591,6 @@ def test(self):
596591
'inner setup', 'inner test', 'inner cleanup',
597592
'end outer test', 'outer cleanup'])
598593

599-
@force_not_colorized
600594
def test_run_empty_suite_error_message(self):
601595
class EmptyTest(unittest.TestCase):
602596
pass
@@ -608,6 +602,7 @@ class EmptyTest(unittest.TestCase):
608602
self.assertIn("\nNO TESTS RAN\n", runner.stream.getvalue())
609603

610604

605+
@force_not_colorized_test_class
611606
class TestModuleCleanUp(unittest.TestCase):
612607
def test_add_and_do_ModuleCleanup(self):
613608
module_cleanups = []
@@ -670,7 +665,6 @@ class Module(object):
670665
self.assertEqual(cleanups,
671666
[((1, 2), {'function': 'hello'})])
672667

673-
@force_not_colorized
674668
def test_run_module_cleanUp(self):
675669
blowUp = True
676670
ordering = []
@@ -810,7 +804,6 @@ def tearDownClass(cls):
810804
'tearDownClass', 'cleanup_good'])
811805
self.assertEqual(unittest.case._module_cleanups, [])
812806

813-
@force_not_colorized
814807
def test_run_module_cleanUp_when_teardown_exception(self):
815808
ordering = []
816809
class Module(object):
@@ -972,7 +965,6 @@ def testNothing(self):
972965
self.assertEqual(cleanups,
973966
[((1, 2), {'function': 3, 'self': 4})])
974967

975-
@force_not_colorized
976968
def test_with_errors_in_addClassCleanup(self):
977969
ordering = []
978970

@@ -1006,7 +998,6 @@ def tearDownClass(cls):
1006998
['setUpModule', 'setUpClass', 'test', 'tearDownClass',
1007999
'cleanup_exc', 'tearDownModule', 'cleanup_good'])
10081000

1009-
@force_not_colorized
10101001
def test_with_errors_in_addCleanup(self):
10111002
ordering = []
10121003
class Module(object):
@@ -1037,7 +1028,6 @@ def tearDown(self):
10371028
['setUpModule', 'setUp', 'test', 'tearDown',
10381029
'cleanup_exc', 'tearDownModule', 'cleanup_good'])
10391030

1040-
@force_not_colorized
10411031
def test_with_errors_in_addModuleCleanup_and_setUps(self):
10421032
ordering = []
10431033
module_blow_up = False

0 commit comments

Comments
 (0)