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

pytest --last-failed does not seem to remember failed subtests #56

Open
chingc opened this issue Dec 14, 2021 · 3 comments
Open

pytest --last-failed does not seem to remember failed subtests #56

chingc opened this issue Dec 14, 2021 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@chingc
Copy link

chingc commented Dec 14, 2021

I'm experiencing an issue where it appears that --last-failed cannot remember a failed test if the failure occurs in a subtest.

As a result, instead of only re-running the failed test --last-failed will re-run all tests.

Additionally, no tests will run if --last-failed is used with --last-failed-no-failure=none.

Here is my test:

def test_fails(subtests):
    for i in range(0, 2):
        with subtests.test(msg="error", i=i):
            assert i == 1

def test_passes():
    assert True

Result with pytest -q

Looks good so far. This is expected output.

============================ FAILURES ============================
____________________ test_fails [error] (i=0) ____________________

    def test_fails(subtests):
        for i in range(0, 2):
            with subtests.test(msg="error", i=i):
>               assert i == 1
E               assert 0 == 1

test_subtest.py:4: AssertionError
==================== short test summary info =====================
FAILED test_subtest.py::test_fails - assert 0 == 1
1 failed, 2 passed, 2 warnings in 0.21s

Result with pytest -q --lf

It's re-running all tests including test_passes which didn't fail. This is unexpected.

============================ FAILURES ============================
____________________ test_fails [error] (i=0) ____________________

    def test_fails(subtests):
        for i in range(0, 2):
            with subtests.test(msg="error", i=i):
>               assert i == 1
E               assert 0 == 1

test_subtest.py:4: AssertionError
==================== short test summary info =====================
FAILED test_subtest.py::test_fails - assert 0 == 1
1 failed, 2 passed, 2 warnings in 0.25s

Result with pytest -q --lf --lfnf=none

This is the worst case because I know something failed and it didn't re-run anything!

2 deselected in 0.01s
@nicoddemus nicoddemus added bug Something isn't working help wanted Extra attention is needed labels Dec 14, 2021
@nicoddemus
Copy link
Member

Thanks for the report @chingc!

@RonnyPfannschmidt
Copy link
Member

i jsut hit this while trying to ease debugging in a codebase

@nicoddemus
Copy link
Member

Yeah currently, if only sub-tests failed, then the parent test passes, so it is not considered by the last-failed plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants