mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
GH-113661: unittest runner: Don't exit 5 if tests were skipped (#113856)
The intention of exiting 5 was to detect issues where the test suite wasn't discovered at all. If we skipped tests, it was correctly discovered.
This commit is contained in:
parent
0297418cac
commit
3a9096c337
5 changed files with 18 additions and 3 deletions
|
|
@ -2290,7 +2290,7 @@ Loading and running tests
|
||||||
The *testRunner* argument can either be a test runner class or an already
|
The *testRunner* argument can either be a test runner class or an already
|
||||||
created instance of it. By default ``main`` calls :func:`sys.exit` with
|
created instance of it. By default ``main`` calls :func:`sys.exit` with
|
||||||
an exit code indicating success (0) or failure (1) of the tests run.
|
an exit code indicating success (0) or failure (1) of the tests run.
|
||||||
An exit code of 5 indicates that no tests were run.
|
An exit code of 5 indicates that no tests were run or skipped.
|
||||||
|
|
||||||
The *testLoader* argument has to be a :class:`TestLoader` instance,
|
The *testLoader* argument has to be a :class:`TestLoader` instance,
|
||||||
and defaults to :data:`defaultTestLoader`.
|
and defaults to :data:`defaultTestLoader`.
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,18 @@ class Test_TestProgram(unittest.TestCase):
|
||||||
'expected failures=1, unexpected successes=1)\n')
|
'expected failures=1, unexpected successes=1)\n')
|
||||||
self.assertTrue(out.endswith(expected))
|
self.assertTrue(out.endswith(expected))
|
||||||
|
|
||||||
|
def test_ExitSkippedSuite(self):
|
||||||
|
stream = BufferedWriter()
|
||||||
|
with self.assertRaises(SystemExit) as cm:
|
||||||
|
unittest.main(
|
||||||
|
argv=["foobar", "-k", "testSkipped"],
|
||||||
|
testRunner=unittest.TextTestRunner(stream=stream),
|
||||||
|
testLoader=self.TestLoader(self.FooBar))
|
||||||
|
self.assertEqual(cm.exception.code, 0)
|
||||||
|
out = stream.getvalue()
|
||||||
|
expected = '\n\nOK (skipped=1)\n'
|
||||||
|
self.assertTrue(out.endswith(expected))
|
||||||
|
|
||||||
def test_ExitEmptySuite(self):
|
def test_ExitEmptySuite(self):
|
||||||
stream = BufferedWriter()
|
stream = BufferedWriter()
|
||||||
with self.assertRaises(SystemExit) as cm:
|
with self.assertRaises(SystemExit) as cm:
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ class TestProgram(object):
|
||||||
testRunner = self.testRunner
|
testRunner = self.testRunner
|
||||||
self.result = testRunner.run(self.test)
|
self.result = testRunner.run(self.test)
|
||||||
if self.exit:
|
if self.exit:
|
||||||
if self.result.testsRun == 0:
|
if self.result.testsRun == 0 and len(self.result.skipped) == 0:
|
||||||
sys.exit(_NO_TESTS_EXITCODE)
|
sys.exit(_NO_TESTS_EXITCODE)
|
||||||
elif self.result.wasSuccessful():
|
elif self.result.wasSuccessful():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ class TextTestRunner(object):
|
||||||
infos.append("failures=%d" % failed)
|
infos.append("failures=%d" % failed)
|
||||||
if errored:
|
if errored:
|
||||||
infos.append("errors=%d" % errored)
|
infos.append("errors=%d" % errored)
|
||||||
elif run == 0:
|
elif run == 0 and not skipped:
|
||||||
self.stream.write("NO TESTS RAN")
|
self.stream.write("NO TESTS RAN")
|
||||||
else:
|
else:
|
||||||
self.stream.write("OK")
|
self.stream.write("OK")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
unittest runner: Don't exit 5 if tests were skipped. The intention of
|
||||||
|
exiting 5 was to detect issues where the test suite wasn't discovered at
|
||||||
|
all. If we skipped tests, it was correctly discovered.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue