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

add support for pytest-subtests #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

radoering
Copy link

@radoering radoering commented Apr 30, 2024

Objective

Select pytest as test runner in PyCharm, even if unit tests that use the subTest feature are executed and still get separate items for the subtests in the report.

Background

unittest can only execute unittest tests but not pytest tests.
pytest can execute unittest tests as well as pytest tests.
However, the (unittest specific) subTest feature is not supported, so that the complete tests are aborted as soon as the first subtest fails. There is a pytest plugin pytest-subtests to support subtests. With the plugin, subtests are supported when executing pytest in a shell. However, PyCharm still does not support subtests if pytest is chosen as test runner because the teamcity pytest plugin does not support this feature.

Results

Example script tests/test_it.py:

class MyTest(unittest.TestCase):
    def test_this(self):
        l = ["a", "b", "c"]
        for x in l:
            with self.subTest(f"test {x}"):
                assert x != "b"

Execute the example tests/test_it.py...

... with test runner unittest:

unittest

-> separate sub tests are displayed

... with test runner pytest (without pytest-subtests):

pytest without pytest-subtests

-> no sub tests are displayed

... with test runner pytest (with pytest-subtests, unpatched teamcity):

pytest with pytest-subtests and unpatched teamcity

-> broken end state looks like tests never finish

... with test runner pytest (with pytest-subtests, patched teamcity):

pytest with pytest-subtests and patched teamcity

-> same as with test runner unittest 🤩

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

Successfully merging this pull request may close these issues.

1 participant