Fix session fixture teardown exceptions being reported as duplicate XFAILs#13909
Closed
FazeelUsmani wants to merge 4 commits intopytest-dev:mainfrom
Closed
Conversation
…FAILs When a session-scoped autouse fixture raises an exception during teardown, and the last test in the suite is marked @pytest.mark.xfail, pytest was incorrectly showing an extra XFAIL line (duplicated) instead of reporting the teardown failure as an ERROR. The root cause was that the xfail handling in pytest_runtest_makereport was being applied to all phases (setup, call, teardown), converting any exception into an xfail result if the test was marked with xfail. This meant that session fixture teardown exceptions were being misreported as expected failures. The fix restricts xfail handling to only apply during the "call" phase. Setup and teardown failures are now properly reported as errors, regardless of xfail markers on the test. This aligns with the principle that xfail should only apply to test execution, not to fixture setup/teardown failures. Fixes pytest-dev#8375
for more information, see https://pre-commit.ci
e105874 to
78bf7fe
Compare
fc068e8 to
55005ee
Compare
Member
|
Duplicate of #13886 (and frankly, that branch being named |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8375
When a
session-scoped autouse fixture raises an exception during teardown, and the last test in the suite is marked@pytest.mark.xfail, pytest was incorrectly showing an extra XFAIL line (duplicated) instead of reporting the teardown failure as an ERROR.Problem
Before this fix:
1 passed, 2 xfailed(incorrect - duplicate xfail)After this fix:
1 passed, 1 xfailed, 1 error(correct)Root Cause
The xfail handling in
pytest_runtest_makereportwas being applied to all test phases (setup, call, teardown). This caused any exception during teardown to be converted to an xfail result if the test was marked with@pytest.mark.xfail.Solution
Restrict xfail handling to only apply during the "call" phase. Setup and teardown failures are now properly reported as errors, regardless of xfail markers on the test.
This aligns with the principle that xfail should only apply to test execution logic, not to fixture infrastructure failures (setup/teardown).
Changes
src/_pytest/skipping.py: Addedif call.when == "call"condition to xfail handlingtest_session_fixture_teardown_exception_with_xfail