1515import sysconfig
1616import tempfile
1717import textwrap
18- import threading
1918import unittest
2019from test import libregrtest
2120from test import support
@@ -67,10 +66,10 @@ def test_wait(self):
6766 ns = libregrtest ._parse_args (['--wait' ])
6867 self .assertTrue (ns .wait )
6968
70- def test_slaveargs (self ):
71- ns = libregrtest ._parse_args (['--slaveargs ' , '[[], {}]' ])
72- self .assertEqual (ns .slaveargs , '[[], {}]' )
73- self .checkError (['--slaveargs ' ], 'expected one argument' )
69+ def test_worker_args (self ):
70+ ns = libregrtest ._parse_args (['--worker-args ' , '[[], {}]' ])
71+ self .assertEqual (ns .worker_args , '[[], {}]' )
72+ self .checkError (['--worker-args ' ], 'expected one argument' )
7473
7574 def test_start (self ):
7675 for opt in '-S' , '--start' :
@@ -352,11 +351,20 @@ def setUp(self):
352351 self .tmptestdir = tempfile .mkdtemp ()
353352 self .addCleanup (support .rmtree , self .tmptestdir )
354353
355- def create_test (self , name = None , code = '' ):
354+ def create_test (self , name = None , code = None ):
356355 if not name :
357356 name = 'noop%s' % BaseTestCase .TEST_UNIQUE_ID
358357 BaseTestCase .TEST_UNIQUE_ID += 1
359358
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+
360368 # test_regrtest cannot be run twice in parallel because
361369 # of setUp() and create_test()
362370 name = self .TESTNAME_PREFIX + name
@@ -391,7 +399,7 @@ def parse_executed_tests(self, output):
391399
392400 def check_executed_tests (self , output , tests , skipped = (), failed = (),
393401 env_changed = (), omitted = (),
394- rerun = (),
402+ rerun = (), no_test_ran = (),
395403 randomize = False , interrupted = False ,
396404 fail_env_changed = False ):
397405 if isinstance (tests , str ):
@@ -406,6 +414,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
406414 omitted = [omitted ]
407415 if isinstance (rerun , str ):
408416 rerun = [rerun ]
417+ if isinstance (no_test_ran , str ):
418+ no_test_ran = [no_test_ran ]
409419
410420 executed = self .parse_executed_tests (output )
411421 if randomize :
@@ -448,8 +458,12 @@ def list_regex(line_format, tests):
448458 regex = "Re-running test %r in verbose mode" % name
449459 self .check_line (output , regex )
450460
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+
451465 good = (len (tests ) - len (skipped ) - len (failed )
452- - len (omitted ) - len (env_changed ))
466+ - len (omitted ) - len (env_changed ) - len ( no_test_ran ) )
453467 if good :
454468 regex = r'%s test%s OK\.$' % (good , plural (good ))
455469 if not skipped and not failed and good > 1 :
@@ -466,12 +480,16 @@ def list_regex(line_format, tests):
466480 result .append ('ENV CHANGED' )
467481 if interrupted :
468482 result .append ('INTERRUPTED' )
469- 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 :
470487 result .append ('SUCCESS' )
471488 result = ', ' .join (result )
472489 if rerun :
473490 self .check_line (output , 'Tests result: %s' % result )
474491 result = 'FAILURE then %s' % result
492+
475493 self .check_line (output , 'Tests result: %s' % result )
476494
477495 def parse_random_seed (self , output ):
@@ -650,7 +668,14 @@ def test_resources(self):
650668 # test -u command line option
651669 tests = {}
652670 for resource in ('audio' , 'network' ):
653- 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+
654679 tests [resource ] = self .create_test (resource , code )
655680 test_names = sorted (tests .values ())
656681
@@ -979,6 +1004,56 @@ def test_bug(self):
9791004 output = self .run_tests ("-w" , testname , exitcode = 2 )
9801005 self .check_executed_tests (output , [testname ],
9811006 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 ])
9821057
9831058
9841059class TestUtils (unittest .TestCase ):
0 commit comments