@@ -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 :
@@ -448,7 +459,7 @@ def list_regex(line_format, tests):
448
459
self .check_line (output , regex )
449
460
450
461
good = (len (tests ) - len (skipped ) - len (failed )
451
- - len (omitted ) - len (env_changed ))
462
+ - len (omitted ) - len (env_changed ) - len ( no_test_ran ) )
452
463
if good :
453
464
regex = r'%s test%s OK\.$' % (good , plural (good ))
454
465
if not skipped and not failed and good > 1 :
@@ -465,12 +476,16 @@ def list_regex(line_format, tests):
465
476
result .append ('ENV CHANGED' )
466
477
if interrupted :
467
478
result .append ('INTERRUPTED' )
468
- if not result :
479
+ if not any ((good , result , failed , interrupted , skipped ,
480
+ env_changed , fail_env_changed )):
481
+ result .append ("NO TEST RUN" )
482
+ elif not result :
469
483
result .append ('SUCCESS' )
470
484
result = ', ' .join (result )
471
485
if rerun :
472
486
self .check_line (output , 'Tests result: %s' % result )
473
487
result = 'FAILURE then %s' % result
488
+
474
489
self .check_line (output , 'Tests result: %s' % result )
475
490
476
491
def parse_random_seed (self , output ):
@@ -649,7 +664,14 @@ def test_resources(self):
649
664
# test -u command line option
650
665
tests = {}
651
666
for resource in ('audio' , 'network' ):
652
- code = 'from test import support\n support.requires(%r)' % resource
667
+ code = textwrap .dedent ("""
668
+ from test import support; support.requires(%r)
669
+ import unittest
670
+ class PassingTest(unittest.TestCase):
671
+ def test_pass(self):
672
+ pass
673
+ """ % resource )
674
+
653
675
tests [resource ] = self .create_test (resource , code )
654
676
test_names = sorted (tests .values ())
655
677
@@ -978,6 +1000,56 @@ def test_bug(self):
978
1000
output = self .run_tests ("-w" , testname , exitcode = 2 )
979
1001
self .check_executed_tests (output , [testname ],
980
1002
failed = testname , rerun = testname )
1003
+ def test_no_tests_ran (self ):
1004
+ code = textwrap .dedent ("""
1005
+ import unittest
1006
+
1007
+ class Tests(unittest.TestCase):
1008
+ def test_bug(self):
1009
+ pass
1010
+ """ )
1011
+ testname = self .create_test (code = code )
1012
+
1013
+ output = self .run_tests (testname , "-m" , "nosuchtest" , exitcode = 0 )
1014
+ self .check_executed_tests (output , [testname ], no_test_ran = testname )
1015
+
1016
+ def test_no_tests_ran_multiple_tests_nonexistent (self ):
1017
+ code = textwrap .dedent ("""
1018
+ import unittest
1019
+
1020
+ class Tests(unittest.TestCase):
1021
+ def test_bug(self):
1022
+ pass
1023
+ """ )
1024
+ testname = self .create_test (code = code )
1025
+ testname2 = self .create_test (code = code )
1026
+
1027
+ output = self .run_tests (testname , testname2 , "-m" , "nosuchtest" , exitcode = 0 )
1028
+ self .check_executed_tests (output , [testname , testname2 ],
1029
+ no_test_ran = [testname , testname2 ])
1030
+
1031
+ def test_no_test_ran_some_test_exist_some_not (self ):
1032
+ code = textwrap .dedent ("""
1033
+ import unittest
1034
+
1035
+ class Tests(unittest.TestCase):
1036
+ def test_bug(self):
1037
+ pass
1038
+ """ )
1039
+ testname = self .create_test (code = code )
1040
+ other_code = textwrap .dedent ("""
1041
+ import unittest
1042
+
1043
+ class Tests(unittest.TestCase):
1044
+ def test_other_bug(self):
1045
+ pass
1046
+ """ )
1047
+ testname2 = self .create_test (code = other_code )
1048
+
1049
+ output = self .run_tests (testname , testname2 , "-m" , "nosuchtest" ,
1050
+ "-m" , "test_other_bug" , exitcode = 0 )
1051
+ self .check_executed_tests (output , [testname , testname2 ],
1052
+ no_test_ran = [testname ])
981
1053
982
1054
983
1055
class TestUtils (unittest .TestCase ):
0 commit comments