Skip to content

Error not raised in session fixture when mark.xfail is set on last test #8375

@romuald

Description

@romuald

Version
6.2.2

Context
Running a test suite with a session fixture that does some cleaning up

Description
If the last test of the suite has a mark.xfail, the error will be marked as an additional xfailed test

Minimal example

import pytest

@pytest.fixture(autouse=True, scope='session')
def failme():
    yield

    raise RuntimeError('cleanup fails for some reason')

def test_01_OK():
    assert 1 == 1

@pytest.mark.xfail()
def test_02_fail():
    assert 0 == 1
% py.test -v test.py
test.py::test_01_OK PASSED
test.py::test_02_fail XFAIL
test.py::test_02_fail XFAIL

To me, it would seem more appropriate to raise the error since the fixture is executed in the context of the session, not the test

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions