Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Open
Description
Bug report
Bug description:
In Python 3.12+,unittest
returns exit code5
when no tests are run and none are skipped. However, if a test class’ssetUpClass()
method raises any exception (exceptunittest.SkipTest
; related to#106584), no tests are executed, and unittest may incorrectly return exit code5
.
This is misleading: the failure occurred due to an error in class-level setup, not because all tests were skipped.
importunittestclassBugTest(unittest.TestCase):@classmethoddefsetUpClass(cls):raiseValueError("Simulated setup failure")deftest_example(self):self.assertTrue(True)
python -m unittest bug_test.pyecho$?
Actual result:
- Exit code is
5
.
Expected result:
- Exit code should be
1
, because an error occurred during test setup.
I think we should report the error first, then check whether no tests are run and none are skipped or not.
https://github.com/python/cpython/blob/3.12/Lib/unittest/main.py#L282-L288
Suggested:
ifself.exit:ifnotself.result.wasSuccessful():sys.exit(1)elifself.result.testsRun==0andlen(self.result.skipped)==0:sys.exit(_NO_TESTS_EXITCODE)else:sys.exit(0)
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Todo