mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-62432: unittest runner: Exit code 5 if no tests were run (#102051)
As discussed in https://discuss.python.org/t/unittest-fail-if-zero-tests-were-discovered/21498/7 It is common for test runner misconfiguration to fail to find any tests, This should be an error. Fixes: #62432
This commit is contained in:
parent
dc3f97549a
commit
76632b836c
8 changed files with 64 additions and 22 deletions
|
@ -9,6 +9,7 @@ from . import loader, runner
|
|||
from .signals import installHandler
|
||||
|
||||
__unittest = True
|
||||
_NO_TESTS_EXITCODE = 5
|
||||
|
||||
MAIN_EXAMPLES = """\
|
||||
Examples:
|
||||
|
@ -279,6 +280,12 @@ class TestProgram(object):
|
|||
testRunner = self.testRunner
|
||||
self.result = testRunner.run(self.test)
|
||||
if self.exit:
|
||||
sys.exit(not self.result.wasSuccessful())
|
||||
if self.result.testsRun == 0:
|
||||
sys.exit(_NO_TESTS_EXITCODE)
|
||||
elif self.result.wasSuccessful():
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
main = TestProgram
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue