Skip to content

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

@timhoffm

Description

@timhoffm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions