Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

unittest may incorrectly return exit code 5 whensetUpClass raises an exception #136442

Open
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@ueshin

Description

@ueshin

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 is5.

Expected result:

  • Exit code should be1, 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

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp