pytest-dev / pytest-dev/pytest

Skipping in a teardown part of a yield fixture is not counted properly

Open
#8,865 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would like to delay skipping tests to the end of the test execution. To do so, I yield from a fixture and call pytest.skip afterwards. This is part of a more complex fixture, but boils down to a minimal example of:

@pytest.fixture()
def post_exec():
    params = {'skip': False}
    yield params
    if params['skip']:
        pytest.skip('This is skipped')

def test_skip(post_exec):
    post_exec['skip'] = True
    # do further stuff

Expected result: The test is skipped.

Actual result: The test appears twice in the statistics

pytest tests/test_x.py::test_skip --v

[...]

tests/test_x.py::test_skip PASSED                                                                  [100%]
tests/test_x.py::test_skip SKIPPED (This is skipped)                                               [100%]

================================================ short test summary info =================================================
SKIPPED [1] tests/text_x.py:207: This is skipped
============================================== 1 passed, 1 skipped in 0.02s ==============================================

Tested with pytest 6.4.2.

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

Reproduce the report with the minimal yield-fixture example and pytest command shown in the issue. Trace fixture teardown and result reporting; done means the test is counted once as skipped, with no passed result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.