Skip to content

Commit

Permalink
bpo-34279: regrtest consider that skipped tests are ran (GH-11132)
Browse files Browse the repository at this point in the history
bpo-34279, bpo-35412: support.run_unittest() no longer raises
TestDidNotRun if a test result contains skipped tests. The
exception is now only raised if no test have been run and no test
have been skipped.
(cherry picked from commit 3a8f4fe)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
  • Loading branch information
miss-islington and vstinner committed Dec 14, 2018
1 parent 5270085 commit 5f252e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ def _run_suite(suite):
if junit_xml_list is not None:
junit_xml_list.append(result.get_xml_element())

if not result.testsRun:
if not result.testsRun and not result.skipped:
raise TestDidNotRun
if not result.wasSuccessful():
if len(result.errors) == 1 and not result.failures:
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ def test_bug(self):
output = self.run_tests("-w", testname, exitcode=2)
self.check_executed_tests(output, [testname],
failed=testname, rerun=testname)

def test_no_tests_ran(self):
code = textwrap.dedent("""
import unittest
Expand All @@ -1017,6 +1018,19 @@ def test_bug(self):
output = self.run_tests(testname, "-m", "nosuchtest", exitcode=0)
self.check_executed_tests(output, [testname], no_test_ran=testname)

def test_no_tests_ran_skip(self):
code = textwrap.dedent("""
import unittest
class Tests(unittest.TestCase):
def test_skipped(self):
self.skipTest("because")
""")
testname = self.create_test(code=code)

output = self.run_tests(testname, exitcode=0)
self.check_executed_tests(output, [testname])

def test_no_tests_ran_multiple_tests_nonexistent(self):
code = textwrap.dedent("""
import unittest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`test.support.run_unittest` no longer raise :exc:`TestDidNotRun` if
the test result contains skipped tests. The exception is now only raised if
no test have been run and no test have been skipped.

0 comments on commit 5f252e1

Please sign in to comment.