Skip to content

Return the correct exit code if all tests have been skipped in unittest #106584

Description

@EliseevEgor

Bug report

In Python 3.12, a new exit code (5, instead of 0) was added if all tests were skipped in unittest. But in some cases it still returns 0. See code examples.

Code example 1:

import unittest


class TestSimple(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        raise unittest.SkipTest("Skip whole Case")

    def test_true(self):
        self.assertTrue(True)

    def test_false(self):
        self.assertTrue(False, msg="Is not True")

Output:

Ran 0 tests in 0.000s

NO TESTS RAN (skipped=1)

Ok, we get exit code 5 here.

Code example 2:

import unittest


class TestCase(unittest.TestCase):
    @unittest.skip("something")
    def test(self):
        self.assertTrue(False)

Output:

Ran 1 test in 0.000s

OK (skipped=1)

Here we can see output 0. Ran one test and skipped. But I think it is incorrect, because all tests were skipped.

Your environment

  • CPython versions tested on: 3.12
  • Operating system and architecture: I think it does not matter.

Linked PRs

Activity

  1. added a commit that references this issue on Jul 10, 2023
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.12only security fixes
    3.13only security fixes
    on Jul 10, 2023
  3. added 4 commits that reference this issue on Jul 11, 2023
  4. added a commit that references this issue on Sep 22, 2023
  5. added a commit that references this issue on Sep 22, 2023
  6. added a commit that references this issue on Sep 28, 2023
  7. added a commit that references this issue on Oct 2, 2023
  8. 1 remaining item

  9. added a commit that references this issue on Jan 23, 2024
  10. serhiy-storchaka commented on Jan 23, 2024

    @serhiy-storchaka
    Member

    I think that it was a wrong change, and not only because it makes startTest() and stopTest() calls unbalanced (#113267), but because it does not solve the original issue. The third example should be equivalent to the second example:

    import unittest
    
    class TestCase(unittest.TestCase):
        def test(self):
            self.skipTest("something")

    But it gets error code 0 while the second example gets error code 5.

    It also gives a wrong answer to the problem. #113661 fixes it in the opposite way.

  11. added a commit that references this issue on Feb 4, 2024
  12. added a commit that references this issue on Feb 4, 2024
  13. added a commit that references this issue on Feb 4, 2024
  14. added a commit that references this issue on Feb 11, 2024
  15. added a commit that references this issue on Feb 14, 2024
  16. carljm commented on Feb 29, 2024

    @carljm
    Member

    Looks like this change has been reverted, and #113661 PRs are merged also, and that issue is closed. Seems there is nothing left to do here?

  17. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions