77import traceback
88import unittest
99from unittest .util import strclass
10+ from test .support import force_not_colorized
1011from test .test_unittest .support import BufferedWriter
1112
1213
1314class MockTraceback (object ):
1415 class TracebackException :
1516 def __init__ (self , * args , ** kwargs ):
1617 self .capture_locals = kwargs .get ('capture_locals' , False )
17- def format (self ):
18+ def format (self , ** kwargs ):
1819 result = ['A traceback' ]
1920 if self .capture_locals :
2021 result .append ('locals' )
@@ -205,6 +206,7 @@ def test_1(self):
205206 self .assertIs (test_case , test )
206207 self .assertIsInstance (formatted_exc , str )
207208
209+ @force_not_colorized
208210 def test_addFailure_filter_traceback_frames (self ):
209211 class Foo (unittest .TestCase ):
210212 def test_1 (self ):
@@ -231,6 +233,7 @@ def get_exc_info():
231233 self .assertEqual (len (dropped ), 1 )
232234 self .assertIn ("raise self.failureException(msg)" , dropped [0 ])
233235
236+ @force_not_colorized
234237 def test_addFailure_filter_traceback_frames_context (self ):
235238 class Foo (unittest .TestCase ):
236239 def test_1 (self ):
@@ -260,6 +263,7 @@ def get_exc_info():
260263 self .assertEqual (len (dropped ), 1 )
261264 self .assertIn ("raise self.failureException(msg)" , dropped [0 ])
262265
266+ @force_not_colorized
263267 def test_addFailure_filter_traceback_frames_chained_exception_self_loop (self ):
264268 class Foo (unittest .TestCase ):
265269 def test_1 (self ):
@@ -285,6 +289,7 @@ def get_exc_info():
285289 formatted_exc = result .failures [0 ][1 ]
286290 self .assertEqual (formatted_exc .count ("Exception: Loop\n " ), 1 )
287291
292+ @force_not_colorized
288293 def test_addFailure_filter_traceback_frames_chained_exception_cycle (self ):
289294 class Foo (unittest .TestCase ):
290295 def test_1 (self ):
@@ -446,6 +451,7 @@ def testFailFast(self):
446451 result .addUnexpectedSuccess (None )
447452 self .assertTrue (result .shouldStop )
448453
454+ @force_not_colorized
449455 def testFailFastSetByRunner (self ):
450456 stream = BufferedWriter ()
451457 runner = unittest .TextTestRunner (stream = stream , failfast = True )
@@ -619,6 +625,7 @@ def _run_test(self, test_name, verbosity, tearDownError=None):
619625 test .run (result )
620626 return stream .getvalue ()
621627
628+ @force_not_colorized
622629 def testDotsOutput (self ):
623630 self .assertEqual (self ._run_test ('testSuccess' , 1 ), '.' )
624631 self .assertEqual (self ._run_test ('testSkip' , 1 ), 's' )
@@ -627,6 +634,7 @@ def testDotsOutput(self):
627634 self .assertEqual (self ._run_test ('testExpectedFailure' , 1 ), 'x' )
628635 self .assertEqual (self ._run_test ('testUnexpectedSuccess' , 1 ), 'u' )
629636
637+ @force_not_colorized
630638 def testLongOutput (self ):
631639 classname = f'{ __name__ } .{ self .Test .__qualname__ } '
632640 self .assertEqual (self ._run_test ('testSuccess' , 2 ),
@@ -642,17 +650,21 @@ def testLongOutput(self):
642650 self .assertEqual (self ._run_test ('testUnexpectedSuccess' , 2 ),
643651 f'testUnexpectedSuccess ({ classname } .testUnexpectedSuccess) ... unexpected success\n ' )
644652
653+ @force_not_colorized
645654 def testDotsOutputSubTestSuccess (self ):
646655 self .assertEqual (self ._run_test ('testSubTestSuccess' , 1 ), '.' )
647656
657+ @force_not_colorized
648658 def testLongOutputSubTestSuccess (self ):
649659 classname = f'{ __name__ } .{ self .Test .__qualname__ } '
650660 self .assertEqual (self ._run_test ('testSubTestSuccess' , 2 ),
651661 f'testSubTestSuccess ({ classname } .testSubTestSuccess) ... ok\n ' )
652662
663+ @force_not_colorized
653664 def testDotsOutputSubTestMixed (self ):
654665 self .assertEqual (self ._run_test ('testSubTestMixed' , 1 ), 'sFE' )
655666
667+ @force_not_colorized
656668 def testLongOutputSubTestMixed (self ):
657669 classname = f'{ __name__ } .{ self .Test .__qualname__ } '
658670 self .assertEqual (self ._run_test ('testSubTestMixed' , 2 ),
@@ -661,6 +673,7 @@ def testLongOutputSubTestMixed(self):
661673 f' testSubTestMixed ({ classname } .testSubTestMixed) [fail] (c=3) ... FAIL\n '
662674 f' testSubTestMixed ({ classname } .testSubTestMixed) [error] (d=4) ... ERROR\n ' )
663675
676+ @force_not_colorized
664677 def testDotsOutputTearDownFail (self ):
665678 out = self ._run_test ('testSuccess' , 1 , AssertionError ('fail' ))
666679 self .assertEqual (out , 'F' )
@@ -671,6 +684,7 @@ def testDotsOutputTearDownFail(self):
671684 out = self ._run_test ('testSkip' , 1 , AssertionError ('fail' ))
672685 self .assertEqual (out , 'sF' )
673686
687+ @force_not_colorized
674688 def testLongOutputTearDownFail (self ):
675689 classname = f'{ __name__ } .{ self .Test .__qualname__ } '
676690 out = self ._run_test ('testSuccess' , 2 , AssertionError ('fail' ))
0 commit comments