Skip to content

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

@dvrogozh

Description

@dvrogozh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions