@@ -351,11 +351,20 @@ def setUp(self):
351
351
self .tmptestdir = tempfile .mkdtemp ()
352
352
self .addCleanup (support .rmtree , self .tmptestdir )
353
353
354
- def create_test (self , name = None , code = '' ):
354
+ def create_test (self , name = None , code = None ):
355
355
if not name :
356
356
name = 'noop%s' % BaseTestCase .TEST_UNIQUE_ID
357
357
BaseTestCase .TEST_UNIQUE_ID += 1
358
358
359
+ if code is None :
360
+ code = textwrap .dedent ("""
361
+ import unittest
362
+
363
+ class Tests(unittest.TestCase):
364
+ def test_empty_test(self):
365
+ pass
366
+ """ )
367
+
359
368
# test_regrtest cannot be run twice in parallel because
360
369
# of setUp() and create_test()
361
370
name = self .TESTNAME_PREFIX + name
@@ -390,7 +399,7 @@ def parse_executed_tests(self, output):
390
399
391
400
def check_executed_tests (self , output , tests , skipped = (), failed = (),
392
401
env_changed = (), omitted = (),
393
- rerun = (),
402
+ rerun = (), no_test_ran = (),
394
403
randomize = False , interrupted = False ,
395
404
fail_env_changed = False ):
396
405
if isinstance (tests , str ):
@@ -405,6 +414,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
405
414
omitted = [omitted ]
406
415
if isinstance (rerun , str ):
407
416
rerun = [rerun ]
417
+ if isinstance (no_test_ran , str ):
418
+ no_test_ran = [no_test_ran ]
408
419
409
420
executed = self .parse_executed_tests (output )
410
421
if randomize :
@@ -447,8 +458,12 @@ def list_regex(line_format, tests):
447
458
regex = "Re-running test %r in verbose mode" % name
448
459
self .check_line (output , regex )
449
460
461
+ if no_test_ran :
462
+ regex = list_regex ('%s test%s run no tests' , no_test_ran )
463
+ self .check_line (output , regex )
464
+
450
465
good = (len (tests ) - len (skipped ) - len (failed )
451
- - len (omitted ) - len (env_changed ))
466
+ - len (omitted ) - len (env_changed ) - len ( no_test_ran ) )
452
467
if good :
453
468
regex = r'%s test%s OK\.$' % (good , plural (good ))
454
469
if not skipped and not failed and good > 1 :
@@ -465,12 +480,16 @@ def list_regex(line_format, tests):
465
480
result .append ('ENV CHANGED' )
466
481
if interrupted :
467
482
result .append ('INTERRUPTED' )
468
- if not result :
483
+ if not any ((good , result , failed , interrupted , skipped ,
484
+ env_changed , fail_env_changed )):
485
+ result .append ("NO TEST RUN" )
486
+ elif not result :
469
487
result .append ('SUCCESS' )
470
488
result = ', ' .join (result )
471
489
if rerun :
472
490
self .check_line (output , 'Tests result: %s' % result )
473
491
result = 'FAILURE then %s' % result
492
+
474
493
self .check_line (output , 'Tests result: %s' % result )
475
494
476
495
def parse_random_seed (self , output ):
@@ -649,7 +668,14 @@ def test_resources(self):
649
668
# test -u command line option
650
669
tests = {}
651
670
for resource in ('audio' , 'network' ):
652
- code = 'from test import support\n support.requires(%r)' % resource
671
+ code = textwrap .dedent ("""
672
+ from test import support; support.requires(%r)
673
+ import unittest
674
+ class PassingTest(unittest.TestCase):
675
+ def test_pass(self):
676
+ pass
677
+ """ % resource )
678
+
653
679
tests [resource ] = self .create_test (resource , code )
654
680
test_names = sorted (tests .values ())
655
681
@@ -978,6 +1004,56 @@ def test_bug(self):
978
1004
output = self .run_tests ("-w" , testname , exitcode = 2 )
979
1005
self .check_executed_tests (output , [testname ],
980
1006
failed = testname , rerun = testname )
1007
+ def test_no_tests_ran (self ):
1008
+ code = textwrap .dedent ("""
1009
+ import unittest
1010
+
1011
+ class Tests(unittest.TestCase):
1012
+ def test_bug(self):
1013
+ pass
1014
+ """ )
1015
+ testname = self .create_test (code = code )
1016
+
1017
+ output = self .run_tests (testname , "-m" , "nosuchtest" , exitcode = 0 )
1018
+ self .check_executed_tests (output , [testname ], no_test_ran = testname )
1019
+
1020
+ def test_no_tests_ran_multiple_tests_nonexistent (self ):
1021
+ code = textwrap .dedent ("""
1022
+ import unittest
1023
+
1024
+ class Tests(unittest.TestCase):
1025
+ def test_bug(self):
1026
+ pass
1027
+ """ )
1028
+ testname = self .create_test (code = code )
1029
+ testname2 = self .create_test (code = code )
1030
+
1031
+ output = self .run_tests (testname , testname2 , "-m" , "nosuchtest" , exitcode = 0 )
1032
+ self .check_executed_tests (output , [testname , testname2 ],
1033
+ no_test_ran = [testname , testname2 ])
1034
+
1035
+ def test_no_test_ran_some_test_exist_some_not (self ):
1036
+ code = textwrap .dedent ("""
1037
+ import unittest
1038
+
1039
+ class Tests(unittest.TestCase):
1040
+ def test_bug(self):
1041
+ pass
1042
+ """ )
1043
+ testname = self .create_test (code = code )
1044
+ other_code = textwrap .dedent ("""
1045
+ import unittest
1046
+
1047
+ class Tests(unittest.TestCase):
1048
+ def test_other_bug(self):
1049
+ pass
1050
+ """ )
1051
+ testname2 = self .create_test (code = other_code )
1052
+
1053
+ output = self .run_tests (testname , testname2 , "-m" , "nosuchtest" ,
1054
+ "-m" , "test_other_bug" , exitcode = 0 )
1055
+ self .check_executed_tests (output , [testname , testname2 ],
1056
+ no_test_ran = [testname ])
981
1057
982
1058
983
1059
class TestUtils (unittest .TestCase ):
0 commit comments