-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix session fixture teardown exceptions being reported as duplicate XFAILs #13886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
FazeelUsmani
wants to merge
2
commits into
pytest-dev:main
Choose a base branch
from
FazeelUsmani:claude/update-commit-author-011CUth8nk5b4ZT9xscUXzwv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−21
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -737,6 +737,11 @@ def test_2(): | |
|
|
||
| class TestXFailwithSetupTeardown: | ||
| def test_failing_setup_issue9(self, pytester: Pytester) -> None: | ||
| """Setup failures should be reported as errors, not xfails. | ||
|
|
||
| Even if a test is marked xfail, if the setup fails, that's an | ||
| infrastructure error, not an expected test failure. | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a major behavior change, which probably warrants some more discussions (and possibly a major release, might be too late for 9.0.0 though). |
||
| pytester.makepyfile( | ||
| """ | ||
| import pytest | ||
|
|
@@ -749,9 +754,14 @@ def test_func(): | |
| """ | ||
| ) | ||
| result = pytester.runpytest() | ||
| result.stdout.fnmatch_lines(["*1 xfail*"]) | ||
| result.stdout.fnmatch_lines(["*1 error*"]) | ||
|
|
||
| def test_failing_teardown_issue9(self, pytester: Pytester) -> None: | ||
| """Teardown failures should be reported as errors, not xfails. | ||
|
|
||
| Even if a test is marked xfail, if the teardown fails, that's an | ||
| infrastructure error, not an expected test failure. | ||
| """ | ||
| pytester.makepyfile( | ||
| """ | ||
| import pytest | ||
|
|
@@ -764,7 +774,7 @@ def test_func(): | |
| """ | ||
| ) | ||
| result = pytester.runpytest() | ||
| result.stdout.fnmatch_lines(["*1 xfail*"]) | ||
| result.stdout.fnmatch_lines(["*1 error*"]) | ||
|
|
||
|
|
||
| class TestSkip: | ||
|
|
@@ -1185,6 +1195,11 @@ def test_default_markers(pytester: Pytester) -> None: | |
|
|
||
|
|
||
| def test_xfail_test_setup_exception(pytester: Pytester) -> None: | ||
| """Setup exceptions should be reported as errors, not xfails. | ||
|
|
||
| Even if a test is marked xfail, if setup fails (via pytest_runtest_setup hook), | ||
| that's an infrastructure error, not an expected test failure. | ||
| """ | ||
| pytester.makeconftest( | ||
| """ | ||
| def pytest_runtest_setup(): | ||
|
|
@@ -1200,9 +1215,9 @@ def test_func(): | |
| """ | ||
| ) | ||
| result = pytester.runpytest(p) | ||
| assert result.ret == 0 | ||
| assert "xfailed" in result.stdout.str() | ||
| result.stdout.no_fnmatch_line("*xpassed*") | ||
| assert result.ret == 1 # Should fail due to error | ||
| assert "error" in result.stdout.str() | ||
| result.stdout.no_fnmatch_line("*xfailed*") | ||
|
|
||
|
|
||
| def test_imperativeskip_on_xfail_test(pytester: Pytester) -> None: | ||
|
|
@@ -1489,3 +1504,37 @@ def test_exit_reason_only(): | |
| ) | ||
| result = pytester.runpytest(p) | ||
| result.stdout.fnmatch_lines("*_pytest.outcomes.Exit: foo*") | ||
|
|
||
|
|
||
| def test_session_fixture_teardown_exception_with_xfail(pytester: Pytester) -> None: | ||
| """Test that session fixture teardown exceptions are reported as errors, | ||
| not as duplicate xfails, even when the last test is marked xfail. | ||
|
|
||
| Regression test for issue #8375. | ||
| """ | ||
| pytester.makepyfile( | ||
| """ | ||
| import pytest | ||
|
|
||
| @pytest.fixture(autouse=True, scope='session') | ||
| def failme(): | ||
| yield | ||
| raise RuntimeError('cleanup fails for some reason') | ||
|
|
||
| def test_ok(): | ||
| assert True | ||
|
|
||
| @pytest.mark.xfail() | ||
| def test_expected_failure(): | ||
| assert False | ||
| """ | ||
| ) | ||
| result = pytester.runpytest("-q") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "*1 passed, 1 xfailed, 1 error*", | ||
| ] | ||
| ) | ||
| # Make sure we don't have duplicate xfails (would be "2 xfailed" before the fix) | ||
| assert "2 xfailed" not in result.stdout.str() | ||
| assert "1 xfailed" in result.stdout.str() | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have an
ifhere already, so you can just combine this toinstead of having to indent everything under a second
if.