pytest-dev / pytest-dev/pytest
Error not raised in session fixture when mark.xfail is set on last test
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal example in test.py with pytest -v and observe the session-fixture cleanup failure after the final xfailed test. Trace how session fixture teardown errors are reported in this execution path. Done means the cleanup RuntimeError is raised or reported as an error rather than recorded as an additional xfailed test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100