7
7
import traceback
8
8
import unittest
9
9
from unittest .util import strclass
10
+ from test .support import force_not_colorized
10
11
from test .test_unittest .support import BufferedWriter
11
12
12
13
13
14
class MockTraceback (object ):
14
15
class TracebackException :
15
16
def __init__ (self , * args , ** kwargs ):
16
17
self .capture_locals = kwargs .get ('capture_locals' , False )
17
- def format (self ):
18
+ def format (self , ** kwargs ):
18
19
result = ['A traceback' ]
19
20
if self .capture_locals :
20
21
result .append ('locals' )
@@ -205,6 +206,7 @@ def test_1(self):
205
206
self .assertIs (test_case , test )
206
207
self .assertIsInstance (formatted_exc , str )
207
208
209
+ @force_not_colorized
208
210
def test_addFailure_filter_traceback_frames (self ):
209
211
class Foo (unittest .TestCase ):
210
212
def test_1 (self ):
@@ -231,6 +233,7 @@ def get_exc_info():
231
233
self .assertEqual (len (dropped ), 1 )
232
234
self .assertIn ("raise self.failureException(msg)" , dropped [0 ])
233
235
236
+ @force_not_colorized
234
237
def test_addFailure_filter_traceback_frames_context (self ):
235
238
class Foo (unittest .TestCase ):
236
239
def test_1 (self ):
@@ -260,6 +263,7 @@ def get_exc_info():
260
263
self .assertEqual (len (dropped ), 1 )
261
264
self .assertIn ("raise self.failureException(msg)" , dropped [0 ])
262
265
266
+ @force_not_colorized
263
267
def test_addFailure_filter_traceback_frames_chained_exception_self_loop (self ):
264
268
class Foo (unittest .TestCase ):
265
269
def test_1 (self ):
@@ -285,6 +289,7 @@ def get_exc_info():
285
289
formatted_exc = result .failures [0 ][1 ]
286
290
self .assertEqual (formatted_exc .count ("Exception: Loop\n " ), 1 )
287
291
292
+ @force_not_colorized
288
293
def test_addFailure_filter_traceback_frames_chained_exception_cycle (self ):
289
294
class Foo (unittest .TestCase ):
290
295
def test_1 (self ):
@@ -446,6 +451,7 @@ def testFailFast(self):
446
451
result .addUnexpectedSuccess (None )
447
452
self .assertTrue (result .shouldStop )
448
453
454
+ @force_not_colorized
449
455
def testFailFastSetByRunner (self ):
450
456
stream = BufferedWriter ()
451
457
runner = unittest .TextTestRunner (stream = stream , failfast = True )
@@ -619,6 +625,7 @@ def _run_test(self, test_name, verbosity, tearDownError=None):
619
625
test .run (result )
620
626
return stream .getvalue ()
621
627
628
+ @force_not_colorized
622
629
def testDotsOutput (self ):
623
630
self .assertEqual (self ._run_test ('testSuccess' , 1 ), '.' )
624
631
self .assertEqual (self ._run_test ('testSkip' , 1 ), 's' )
@@ -627,6 +634,7 @@ def testDotsOutput(self):
627
634
self .assertEqual (self ._run_test ('testExpectedFailure' , 1 ), 'x' )
628
635
self .assertEqual (self ._run_test ('testUnexpectedSuccess' , 1 ), 'u' )
629
636
637
+ @force_not_colorized
630
638
def testLongOutput (self ):
631
639
classname = f'{ __name__ } .{ self .Test .__qualname__ } '
632
640
self .assertEqual (self ._run_test ('testSuccess' , 2 ),
@@ -642,17 +650,21 @@ def testLongOutput(self):
642
650
self .assertEqual (self ._run_test ('testUnexpectedSuccess' , 2 ),
643
651
f'testUnexpectedSuccess ({ classname } .testUnexpectedSuccess) ... unexpected success\n ' )
644
652
653
+ @force_not_colorized
645
654
def testDotsOutputSubTestSuccess (self ):
646
655
self .assertEqual (self ._run_test ('testSubTestSuccess' , 1 ), '.' )
647
656
657
+ @force_not_colorized
648
658
def testLongOutputSubTestSuccess (self ):
649
659
classname = f'{ __name__ } .{ self .Test .__qualname__ } '
650
660
self .assertEqual (self ._run_test ('testSubTestSuccess' , 2 ),
651
661
f'testSubTestSuccess ({ classname } .testSubTestSuccess) ... ok\n ' )
652
662
663
+ @force_not_colorized
653
664
def testDotsOutputSubTestMixed (self ):
654
665
self .assertEqual (self ._run_test ('testSubTestMixed' , 1 ), 'sFE' )
655
666
667
+ @force_not_colorized
656
668
def testLongOutputSubTestMixed (self ):
657
669
classname = f'{ __name__ } .{ self .Test .__qualname__ } '
658
670
self .assertEqual (self ._run_test ('testSubTestMixed' , 2 ),
@@ -661,6 +673,7 @@ def testLongOutputSubTestMixed(self):
661
673
f' testSubTestMixed ({ classname } .testSubTestMixed) [fail] (c=3) ... FAIL\n '
662
674
f' testSubTestMixed ({ classname } .testSubTestMixed) [error] (d=4) ... ERROR\n ' )
663
675
676
+ @force_not_colorized
664
677
def testDotsOutputTearDownFail (self ):
665
678
out = self ._run_test ('testSuccess' , 1 , AssertionError ('fail' ))
666
679
self .assertEqual (out , 'F' )
@@ -671,6 +684,7 @@ def testDotsOutputTearDownFail(self):
671
684
out = self ._run_test ('testSkip' , 1 , AssertionError ('fail' ))
672
685
self .assertEqual (out , 'sF' )
673
686
687
+ @force_not_colorized
674
688
def testLongOutputTearDownFail (self ):
675
689
classname = f'{ __name__ } .{ self .Test .__qualname__ } '
676
690
out = self ._run_test ('testSuccess' , 2 , AssertionError ('fail' ))
0 commit comments