pytest-dev / pytest-dev/pytest

Test listed twice when there's an error during teardown

Open
#1,004 12 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: help wanted topic: reporting type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

With this code:

import pytest

@pytest.yield_fixture
def fixt():
    yield
    raise Exception

def test_foo(fixt):
    pass

We get this output:

collected 1 items 

py/test_foo.py::test_foo PASSED
py/test_foo.py::test_foo ERROR

================================== ERRORS ===================================
_______________________ ERROR at teardown of test_foo _______________________

    @pytest.yield_fixture
    def fixt():
        yield
>       raise Exception
E       Exception

py/test_foo.py:6: Exception
===================== 1 passed, 1 error in 0.41 seconds ====================

The test obviously only should be listed once, and no passed tests should be listed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the yield_fixture and test_foo example from the report, then trace the test reporting path that handles teardown errors. Done means the test is listed once and is not reported as passed when teardown raises an exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.