◐ Shell
clean mode source ↗

[2.7] bpo-34279, regrtest: Issue a warning if no tests have been executed by vstinner · Pull Request #10801 · python/cpython

Expand Up @@ -51,11 +51,24 @@ def setUp(self): self.tmptestdir = tempfile.mkdtemp() self.addCleanup(support.rmtree, self.tmptestdir)
def create_test(self, name=None, code=''): def create_test(self, name=None, code=None): if not name: name = 'noop%s' % BaseTestCase.TEST_UNIQUE_ID BaseTestCase.TEST_UNIQUE_ID += 1
if code is None: code = textwrap.dedent(""" import unittest from test import support
class Tests(unittest.TestCase): def test_empty_test(self): pass
def test_main(): support.run_unittest(Tests) """)
# test_regrtest cannot be run twice in parallel because # of setUp() and create_test() name = self.TESTNAME_PREFIX + name Expand Down Expand Up @@ -94,7 +107,7 @@ def parse_executed_tests(self, output):
def check_executed_tests(self, output, tests, skipped=(), failed=(), env_changed=(), omitted=(), rerun=(), rerun=(), no_test_ran=(), randomize=False, interrupted=False, fail_env_changed=False): if isinstance(tests, str): Expand All @@ -109,6 +122,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(), omitted = [omitted] if isinstance(rerun, str): rerun = [rerun] if isinstance(no_test_ran, str): no_test_ran = [no_test_ran]
executed = self.parse_executed_tests(output) if randomize: Expand Down Expand Up @@ -152,7 +167,7 @@ def list_regex(line_format, tests): self.check_line(output, regex)
good = (len(tests) - len(skipped) - len(failed) - len(omitted) - len(env_changed)) - len(omitted) - len(env_changed) - len(no_test_ran)) if good: regex = r'%s test%s OK\.$' % (good, plural(good)) if not skipped and not failed and good > 1: Expand All @@ -169,12 +184,16 @@ def list_regex(line_format, tests): result.append('ENV CHANGED') if interrupted: result.append('INTERRUPTED') if not result: if not any((good, result, failed, interrupted, skipped, env_changed, fail_env_changed)): result.append("NO TEST RUN") elif not result: result.append('SUCCESS') result = ', '.join(result) if rerun: self.check_line(output, 'Tests result: %s' % result) result = 'FAILURE then %s' % result
self.check_line(output, 'Tests result: %s' % result)
def parse_random_seed(self, output): Expand Down Expand Up @@ -358,7 +377,17 @@ def test_resources(self): # test -u command line option tests = {} for resource in ('audio', 'network'): code = 'from test import support\nsupport.requires(%r)' % resource code = textwrap.dedent(""" from test import support; support.requires(%r) import unittest class PassingTest(unittest.TestCase): def test_pass(self): pass
def test_main(): support.run_unittest(PassingTest) """ % resource)
tests[resource] = self.create_test(resource, code) test_names = sorted(tests.values())
Expand Down Expand Up @@ -669,6 +698,7 @@ def test_main(): def test_rerun_fail(self): code = textwrap.dedent(""" import unittest from test import support
class Tests(unittest.TestCase): def test_bug(self): Expand All @@ -684,6 +714,76 @@ def test_main(): self.check_executed_tests(output, [testname], failed=testname, rerun=testname)
def test_no_tests_ran(self): code = textwrap.dedent(""" import unittest from test import support
class Tests(unittest.TestCase): def test_bug(self): pass
def test_main(): support.run_unittest(Tests) """) testname = self.create_test(code=code)
output = self.run_tests("-m", "nosuchtest", testname, exitcode=0) self.check_executed_tests(output, [testname], no_test_ran=testname)
def test_no_tests_ran_multiple_tests_nonexistent(self): code = textwrap.dedent(""" import unittest from test import support
class Tests(unittest.TestCase): def test_bug(self): pass
def test_main(): support.run_unittest(Tests) """) testname = self.create_test(code=code) testname2 = self.create_test(code=code)
output = self.run_tests("-m", "nosuchtest", testname, testname2, exitcode=0) self.check_executed_tests(output, [testname, testname2], no_test_ran=[testname, testname2])
def test_no_test_ran_some_test_exist_some_not(self): code = textwrap.dedent(""" import unittest from test import support
class Tests(unittest.TestCase): def test_bug(self): pass
def test_main(): support.run_unittest(Tests) """) testname = self.create_test(code=code) other_code = textwrap.dedent(""" import unittest from test import support
class Tests(unittest.TestCase): def test_other_bug(self): pass
def test_main(): support.run_unittest(Tests) """) testname2 = self.create_test(code=other_code)
output = self.run_tests("-m", "nosuchtest", "-m", "test_other_bug", testname, testname2, exitcode=0) self.check_executed_tests(output, [testname, testname2], no_test_ran=[testname])

class TestUtils(unittest.TestCase): def test_format_duration(self): Expand Down