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

Issues counting passing rates on tests which use subTest() #34755

Open
dvrogozh opened this issue Nov 15, 2024 · 3 comments
Open

Issues counting passing rates on tests which use subTest() #34755

dvrogozh opened this issue Nov 15, 2024 · 3 comments

Comments

@dvrogozh
Copy link
Contributor

As we discussed in #34723 (comment), we spotted that tests using with self.subTest along with self.skipTest() report confusing passing rates. We need to understand how we should handle this. Below is breakdown of behavior on few syntetic tests.

Note:

Synthetic tests:

  • ex0.py - subTest() without skipping:
$ cat ex0.py
import unittest
class T(unittest.TestCase):
    def test_foo(self):
        for i in range(7):
            with self.subTest(i=i):
                self.assertLess(i, 3)
  • ex1.py - subTest() with skipping:
$ cat ex1.py
import unittest
class T(unittest.TestCase):
    def test_foo(self):
        for i in range(7):
            with self.subTest(i=i):
                if i < 3:
                    self.skipTest(f"bon {i}")
                self.assertLess(i, 3)

Failed Passed Skipped
No pytest-subtests ex0.py 1 0 0
No pytest-subtests ex1.py 0 0 1
With pytest-subtests ex0.py 4 1 0
With pytest-subtests ex1.py 1 1 3

Logs:

  • With pytest-subtests:
$ python -m pytest ex0.py
...
(i=3) SUBFAIL ex0.py::T::test_foo - AssertionError: 3 not less than 3
(i=4) SUBFAIL ex0.py::T::test_foo - AssertionError: 4 not less than 3
(i=5) SUBFAIL ex0.py::T::test_foo - AssertionError: 5 not less than 3
(i=6) SUBFAIL ex0.py::T::test_foo - AssertionError: 6 not less than 3
=================================== 4 failed, 1 passed in 0.11s ===================================

$ python -m pytest ex1.py
...
(i=6) SUBFAIL ex1.py::T::test_foo - AssertionError: 6 not less than 3
============================= 1 failed, 1 passed, 3 skipped in 0.11s ===
  • No pytest-subtests:
$ python -m pytest ex0.py
FAILED ex0.py::T::test_foo - AssertionError: 3 not less than 3
======================================== 1 failed in 0.11s ========================================


$ python -m pytest ex1.py
...
======================================= 1 skipped in 0.07s ========================================

CC: @ydshieh @ArthurZucker

@ydshieh
Copy link
Collaborator

ydshieh commented Nov 15, 2024

It turns out this is related to pytest interacting with unittest and subTest/skipTest.

If running with python3 ex1.py (or ex0.py) with those files with ending

if __name__ == "__main__":
    unittest.main()

then subTest/skipTest works well together ...

@dvrogozh
Copy link
Contributor Author

There are couple open issues which probably worth mentioning:

@ydshieh
Copy link
Collaborator

ydshieh commented Nov 18, 2024

Opening an pull request in

pytest-dev/pytest-subtests#169

Might take some time to be merged (if it happens)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants