diff options
author | Stefano Rivera <stefano@rivera.za.net> | 2023-04-27 01:28:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 01:28:46 (GMT) |
commit | 76632b836cf81a95301f4eb1fa43682e8d9ffa67 (patch) | |
tree | e34dfe04b641f614b06423ff7abd853d765e452d /Lib/unittest | |
parent | dc3f97549a8fe4f7fea8d0326e394760b51caa6e (diff) | |
download | cpython-76632b836cf81a95301f4eb1fa43682e8d9ffa67.zip cpython-76632b836cf81a95301f4eb1fa43682e8d9ffa67.tar.gz cpython-76632b836cf81a95301f4eb1fa43682e8d9ffa67.tar.bz2 |
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
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/main.py | 9 | ||||
-rw-r--r-- | Lib/unittest/runner.py | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index 0792750..51b81a6 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -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 diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py index a51c5c5..e3c020e 100644 --- a/Lib/unittest/runner.py +++ b/Lib/unittest/runner.py @@ -274,6 +274,8 @@ class TextTestRunner(object): infos.append("failures=%d" % failed) if errored: infos.append("errors=%d" % errored) + elif run == 0: + self.stream.write("NO TESTS RAN") else: self.stream.write("OK") if skipped: |