Skip to content

Commit 5f252e1

Browse files
bpo-34279: regrtest consider that skipped tests are ran (GH-11132)
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>
1 parent 5270085 commit 5f252e1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ def _run_suite(suite):
18971897
if junit_xml_list is not None:
18981898
junit_xml_list.append(result.get_xml_element())
18991899

1900-
if not result.testsRun:
1900+
if not result.testsRun and not result.skipped:
19011901
raise TestDidNotRun
19021902
if not result.wasSuccessful():
19031903
if len(result.errors) == 1 and not result.failures:

Lib/test/test_regrtest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ def test_bug(self):
10041004
output = self.run_tests("-w", testname, exitcode=2)
10051005
self.check_executed_tests(output, [testname],
10061006
failed=testname, rerun=testname)
1007+
10071008
def test_no_tests_ran(self):
10081009
code = textwrap.dedent("""
10091010
import unittest
@@ -1017,6 +1018,19 @@ def test_bug(self):
10171018
output = self.run_tests(testname, "-m", "nosuchtest", exitcode=0)
10181019
self.check_executed_tests(output, [testname], no_test_ran=testname)
10191020

1021+
def test_no_tests_ran_skip(self):
1022+
code = textwrap.dedent("""
1023+
import unittest
1024+
1025+
class Tests(unittest.TestCase):
1026+
def test_skipped(self):
1027+
self.skipTest("because")
1028+
""")
1029+
testname = self.create_test(code=code)
1030+
1031+
output = self.run_tests(testname, exitcode=0)
1032+
self.check_executed_tests(output, [testname])
1033+
10201034
def test_no_tests_ran_multiple_tests_nonexistent(self):
10211035
code = textwrap.dedent("""
10221036
import unittest
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`test.support.run_unittest` no longer raise :exc:`TestDidNotRun` if
2+
the test result contains skipped tests. The exception is now only raised if
3+
no test have been run and no test have been skipped.

0 commit comments

Comments
 (0)