5
5
import warnings
6
6
7
7
from . import result
8
+ from .case import _SubTest
8
9
from .signals import registerResult
9
10
10
11
__unittest = True
@@ -40,6 +41,7 @@ def __init__(self, stream, descriptions, verbosity):
40
41
self .showAll = verbosity > 1
41
42
self .dots = verbosity == 1
42
43
self .descriptions = descriptions
44
+ self ._newline = True
43
45
44
46
def getDescription (self , test ):
45
47
doc_first_line = test .shortDescription ()
@@ -54,39 +56,64 @@ def startTest(self, test):
54
56
self .stream .write (self .getDescription (test ))
55
57
self .stream .write (" ... " )
56
58
self .stream .flush ()
59
+ self ._newline = False
60
+
61
+ def _write_status (self , test , status ):
62
+ is_subtest = isinstance (test , _SubTest )
63
+ if is_subtest or self ._newline :
64
+ if not self ._newline :
65
+ self .stream .writeln ()
66
+ if is_subtest :
67
+ self .stream .write (" " )
68
+ self .stream .write (self .getDescription (test ))
69
+ self .stream .write (" ... " )
70
+ self .stream .writeln (status )
71
+ self .stream .flush ()
72
+ self ._newline = True
73
+
74
+ def addSubTest (self , test , subtest , err ):
75
+ if err is not None :
76
+ if self .showAll :
77
+ if issubclass (err [0 ], subtest .failureException ):
78
+ self ._write_status (subtest , "FAIL" )
79
+ else :
80
+ self ._write_status (subtest , "ERROR" )
81
+ elif self .dots :
82
+ if issubclass (err [0 ], subtest .failureException ):
83
+ self .stream .write ('F' )
84
+ else :
85
+ self .stream .write ('E' )
86
+ self .stream .flush ()
87
+ super (TextTestResult , self ).addSubTest (test , subtest , err )
57
88
58
89
def addSuccess (self , test ):
59
90
super (TextTestResult , self ).addSuccess (test )
60
91
if self .showAll :
61
- self .stream .writeln ("ok" )
62
- self .stream .flush ()
92
+ self ._write_status (test , "ok" )
63
93
elif self .dots :
64
94
self .stream .write ('.' )
65
95
self .stream .flush ()
66
96
67
97
def addError (self , test , err ):
68
98
super (TextTestResult , self ).addError (test , err )
69
99
if self .showAll :
70
- self .stream .writeln ("ERROR" )
71
- self .stream .flush ()
100
+ self ._write_status (test , "ERROR" )
72
101
elif self .dots :
73
102
self .stream .write ('E' )
74
103
self .stream .flush ()
75
104
76
105
def addFailure (self , test , err ):
77
106
super (TextTestResult , self ).addFailure (test , err )
78
107
if self .showAll :
79
- self .stream .writeln ("FAIL" )
80
- self .stream .flush ()
108
+ self ._write_status (test , "FAIL" )
81
109
elif self .dots :
82
110
self .stream .write ('F' )
83
111
self .stream .flush ()
84
112
85
113
def addSkip (self , test , reason ):
86
114
super (TextTestResult , self ).addSkip (test , reason )
87
115
if self .showAll :
88
- self .stream .writeln ("skipped {0!r}" .format (reason ))
89
- self .stream .flush ()
116
+ self ._write_status (test , "skipped {0!r}" .format (reason ))
90
117
elif self .dots :
91
118
self .stream .write ("s" )
92
119
self .stream .flush ()
@@ -115,6 +142,12 @@ def printErrors(self):
115
142
self .stream .flush ()
116
143
self .printErrorList ('ERROR' , self .errors )
117
144
self .printErrorList ('FAIL' , self .failures )
145
+ unexpectedSuccesses = getattr (self , 'unexpectedSuccesses' , ())
146
+ if unexpectedSuccesses :
147
+ self .stream .writeln (self .separator1 )
148
+ for test in unexpectedSuccesses :
149
+ self .stream .writeln (f"UNEXPECTED SUCCESS: { self .getDescription (test )} " )
150
+ self .stream .flush ()
118
151
119
152
def printErrorList (self , flavour , errors ):
120
153
for test , err in errors :
@@ -167,15 +200,6 @@ def run(self, test):
167
200
if self .warnings :
168
201
# if self.warnings is set, use it to filter all the warnings
169
202
warnings .simplefilter (self .warnings )
170
- # if the filter is 'default' or 'always', special-case the
171
- # warnings from the deprecated unittest methods to show them
172
- # no more than once per module, because they can be fairly
173
- # noisy. The -Wd and -Wa flags can be used to bypass this
174
- # only when self.warnings is None.
175
- if self .warnings in ['default' , 'always' ]:
176
- warnings .filterwarnings ('module' ,
177
- category = DeprecationWarning ,
178
- message = r'Please use assert\w+ instead.' )
179
203
startTime = time .perf_counter ()
180
204
startTestRun = getattr (result , 'startTestRun' , None )
181
205
if startTestRun is not None :
0 commit comments