@@ -263,7 +263,7 @@ def run(self, result):
263
263
264
264
265
265
class TestRunner :
266
- def run (self , suite ):
266
+ def run (self , suite : TestSuite ):
267
267
res = TestResult ()
268
268
suite .run (res )
269
269
@@ -292,7 +292,8 @@ def __init__(self):
292
292
self .testsRun = 0
293
293
self .errors = []
294
294
self .failures = []
295
- self .newFailures = 0
295
+ self .skipped = []
296
+ self ._newFailures = 0
296
297
297
298
def wasSuccessful (self ):
298
299
return self .errorsNum == 0 and self .failuresNum == 0
@@ -326,6 +327,7 @@ def __add__(self, other):
326
327
self .testsRun += other .testsRun
327
328
self .errors .extend (other .errors )
328
329
self .failures .extend (other .failures )
330
+ self .skipped .extend (other .skipped )
329
331
return self
330
332
331
333
@@ -354,10 +356,10 @@ def handle_test_exception(
354
356
test_result .errors .append ((current_test , ex_str ))
355
357
if verbose :
356
358
print (" ERROR" )
357
- test_result .newFailures += 1
359
+ test_result ._newFailures += 1
358
360
359
361
360
- def run_suite (c , test_result , suite_name = "" ):
362
+ def run_suite (c , test_result : TestResult , suite_name = "" ):
361
363
if isinstance (c , TestSuite ):
362
364
c .run (test_result )
363
365
return
@@ -384,19 +386,21 @@ def run_one(test_function):
384
386
test_container = f"({ suite_name } )"
385
387
__current_test__ = (name , test_container )
386
388
try :
387
- test_result .newFailures = 0
389
+ test_result ._newFailures = 0
388
390
test_result .testsRun += 1
389
391
test_globals = dict (** globals ())
390
392
test_globals ["test_function" ] = test_function
391
393
exec ("test_function()" , test_globals , test_globals )
392
394
# No exception occurred, test passed
393
- if test_result .newFailures :
395
+ if test_result ._newFailures :
394
396
print (" FAIL" )
395
397
else :
396
398
print (" ok" )
397
399
except SkipTest as e :
398
- print (" skipped:" , e .args [0 ])
400
+ reason = e .args [0 ]
401
+ print (" skipped:" , reason )
399
402
test_result .skippedNum += 1
403
+ test_result .skipped .append ((name , c , reason ))
400
404
except Exception as ex :
401
405
handle_test_exception (
402
406
current_test = (name , c ), test_result = test_result , exc_info = sys .exc_info ()
@@ -477,8 +481,14 @@ def discover(runner: TestRunner):
477
481
return discover (runner = runner )
478
482
479
483
480
- def main (module = "__main__" ):
481
- runner = TestRunner ()
484
+ def main (module = "__main__" , testRunner = None ):
485
+ if testRunner :
486
+ if isinstance (testRunner , type ):
487
+ runner = testRunner ()
488
+ else :
489
+ runner = testRunner
490
+ else :
491
+ runner = TestRunner ()
482
492
483
493
if len (sys .argv ) <= 1 :
484
494
result = discover (runner )
0 commit comments