Skip to content

Pytest shows the test as passed even though all its subtests failed #205

@sashko1988

Description

@sashko1988

Pytest shows the test as passed even though all its subtests failed.

Should it be the other way around - if any subtest fails, the main test will fail as well?

Installed versions:

❯ pip list | grep pytest
pytest                        8.4.0
pytest-subtests               0.14.2

Test example:

def test_with_subtets(subtests):

    for i in range(1):
        with subtests.test(msg="custom message", i=i):
            assert False

Expected result: 1 failed.
Actual result: 1 failed, 1 passed

❯ pytest test_with_sub_exs.py -v
======================================== test session starts =========================================
platform darwin -- Python 3.13.5, pytest-8.4.0, pluggy-1.6.0
cachedir: .pytest_cache
configfile: pyproject.toml
plugins: allure-pytest-2.14.2, xdist-3.7.0, instafail-0.5.0, anyio-4.9.0, check-2.5.3, mock-3.14.1, subtests-0.14.2, cov-6.1.1
collected 1 item

test_with_sub_exs.py::test_with_subtets [custom message] (i=0) SUBFAIL                         [100%]
test_with_sub_exs.py::test_with_subtets PASSED                                                 [100%]

============================================== FAILURES ==============================================
______________________________ test_with_subtets [custom message] (i=0) ______________________________

subtests = SubTests(ihook=<_pytest.config.compat.PathAwareHookProxy object at 0x10395c2f0>, suspend_capture_ctx=<bound method Cap...tarted' _in_suspended=False> _capture_fixture=None>>, request=<SubRequest 'subtests' for <Function test_with_subtets>>)

    def test_with_subtets(subtests):
        """Example test using subtests to check even numbers in a range."""

        for i in range(1):
            with subtests.test(msg="custom message", i=i):
>               assert False
E               assert False

test_with_sub_exs.py:6: AssertionError
----------------------------------------- Captured log call ------------------------------------------

====================================== short test summary info =======================================
[custom message] (i=0) SUBFAIL test_with_sub_exs.py::test_with_subtets - assert False
==================================== 1 failed, 1 passed in 0.05s =====================================

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