Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
EliseevEgor opened this issue Jul 10, 2023 · 3 comments
Closed
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@EliseevEgor
Copy link
Contributor

EliseevEgor commented Jul 10, 2023

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

@EliseevEgor EliseevEgor added the type-bug An unexpected behavior, bug, or error label Jul 10, 2023
EliseevEgor added a commit to EliseevEgor/cpython that referenced this issue Jul 10, 2023
Increase the number of running tests only if it hasn't been skipped.
@AlexWaygood AlexWaygood added stdlib Python modules in the Lib dir 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Jul 10, 2023
EliseevEgor added a commit to EliseevEgor/cpython that referenced this issue Jul 11, 2023
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
EliseevEgor added a commit to EliseevEgor/cpython that referenced this issue Jul 11, 2023
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
EliseevEgor added a commit to EliseevEgor/cpython that referenced this issue Jul 11, 2023
EliseevEgor added a commit to EliseevEgor/cpython that referenced this issue Jul 11, 2023
ambv pushed a commit that referenced this issue Sep 22, 2023
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 22, 2023
…106588)

(cherry picked from commit 8fc0713)

Co-authored-by: EliseevEgor <egor.eliseev@jetbrains.com>
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
csm10495 pushed a commit to csm10495/cpython that referenced this issue Sep 28, 2023
…6588)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Yhg1s pushed a commit that referenced this issue Oct 2, 2023
… (#109725)

gh-106584: Fix exit code for unittest in Python 3.12 (GH-106588)
(cherry picked from commit 8fc0713)

Co-authored-by: EliseevEgor <egor.eliseev@jetbrains.com>
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@hugovk
Copy link
Member

hugovk commented Nov 10, 2023

Thank you for the fix!

@serhiy-storchaka
Copy link
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.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 4, 2024
…in Python 3.12 (pythonGH-106588)" (pythonGH-114470)

This reverts commit 8fc0713.
(cherry picked from commit ecabff9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Feb 4, 2024
…thon 3.12 (GH-106588)" (GH-114470) (GH-114994)

This reverts commit 8fc0713.
(cherry picked from commit ecabff9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this issue Feb 14, 2024
@carljm
Copy link
Member

carljm commented Feb 29, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

5 participants