@@ -156,8 +156,10 @@ def __init__(self, test_result, test_method, outcome=SUCCESS, err=None, subTest=
156
156
157
157
self .test_name = testcase_name (test_method )
158
158
self .test_id = test_method .id ()
159
+ self .subDescription = None
159
160
if subTest :
160
161
self .test_id = subTest .id ()
162
+ self .subDescription = subTest ._subDescription ()
161
163
162
164
def id (self ):
163
165
return self .test_id
@@ -174,7 +176,12 @@ def get_description(self):
174
176
"""
175
177
Return a text representation of the test method.
176
178
"""
177
- return self .test_description
179
+ description = self .test_description
180
+
181
+ if self .subDescription is not None :
182
+ description += ' ' + self .subDescription
183
+
184
+ return description
178
185
179
186
def get_error_info (self ):
180
187
"""
@@ -337,14 +344,29 @@ def addSubTest(self, testcase, test, err):
337
344
Called when a subTest method raises an error.
338
345
"""
339
346
if err is not None :
347
+
348
+ errorText = None
349
+ errorValue = None
350
+ errorList = None
351
+ if issubclass (err [0 ], test .failureException ):
352
+ errorText = 'FAIL'
353
+ errorValue = self .infoclass .FAILURE
354
+ errorList = self .failures
355
+
356
+ else :
357
+ errorText = 'ERROR'
358
+ errorValue = self .infoclass .ERROR
359
+ errorList = self .errors
360
+
340
361
self ._save_output_data ()
362
+
341
363
testinfo = self .infoclass (
342
- self , testcase , self . infoclass . ERROR , err , subTest = test )
343
- self . errors .append ((
364
+ self , testcase , errorValue , err , subTest = test )
365
+ errorList .append ((
344
366
testinfo ,
345
367
self ._exc_info_to_string (err , testcase )
346
368
))
347
- self ._prepare_callback (testinfo , [], 'ERROR' , 'E' )
369
+ self ._prepare_callback (testinfo , [], errorText , errorText [ 0 ] )
348
370
349
371
def addSkip (self , test , reason ):
350
372
"""
@@ -356,6 +378,36 @@ def addSkip(self, test, reason):
356
378
self .skipped .append ((testinfo , reason ))
357
379
self ._prepare_callback (testinfo , [], 'SKIP' , 'S' )
358
380
381
+ def addExpectedFailure (self , test , err ):
382
+ """
383
+ Missing in xmlrunner, copy-pasted from xmlrunner addError.
384
+ """
385
+ self ._save_output_data ()
386
+
387
+ testinfo = self .infoclass (self , test , self .infoclass .ERROR , err )
388
+ testinfo .test_exception_name = 'ExpectedFailure'
389
+ testinfo .test_exception_message = 'EXPECTED FAILURE: {}' .format (testinfo .test_exception_message )
390
+
391
+ self .expectedFailures .append ((testinfo , self ._exc_info_to_string (err , test )))
392
+ self ._prepare_callback (testinfo , [], 'EXPECTED FAILURE' , 'X' )
393
+
394
+ @failfast
395
+ def addUnexpectedSuccess (self , test ):
396
+ """
397
+ Missing in xmlrunner, copy-pasted from xmlrunner addSuccess.
398
+ """
399
+ self ._save_output_data ()
400
+
401
+ testinfo = self .infoclass (self , test ) # do not set outcome here because it will need exception
402
+ testinfo .outcome = self .infoclass .ERROR
403
+ # But since we want to have error outcome, we need to provide additional fields:
404
+ testinfo .test_exception_name = 'UnexpectedSuccess'
405
+ testinfo .test_exception_message = ('UNEXPECTED SUCCESS: This test was marked as expected failure but passed, '
406
+ 'please review it' )
407
+
408
+ self .unexpectedSuccesses .append (testinfo )
409
+ self ._prepare_callback (testinfo , [], 'UNEXPECTED SUCCESS' , 'U' )
410
+
359
411
def printErrorList (self , flavour , errors ):
360
412
"""
361
413
Writes information about the FAIL or ERROR to the stream.
0 commit comments