-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Pytest aborts when fixture errors during teardown and --maxfail=1
#11706
Comments
--maxfail=1
leads to pytest aborting--maxfail=1
Note that this also happens when the fixture is |
--maxfail=1
--maxfail=1
This is an interesting edge case you've stumbled upon. Backgroundpytest's setups/teardowns are managed by the You can see the docstring for how it works, but the important part here is that we're tearing down some When ProblemLet's call the Nth failing test "test N" and assume there is at least one test after it, "test N + 1", which shares some higher-scoped fixtures. "test N" is torn down with To fix this, pytest in a last ditch effort runs the remaining teardowns in a But this Possible solution 1Catch the exceptions from the This would work, however then the teardown failures aren't reported in the context of any test. In particular they won't show in any xml reports and such. Possible solution 2Detect when an item had set This would work and run the teardowns in the context of the test, but is a bit dangerous - doesn't handle the case where plugins reset |
Thanks for the detailed reply @bluetech! The real pain point here is the lack of reporting - my team's observability tools consume |
This was pretty easy to implement, basically a one-line change in def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None:
_update_current_test_var(item, "teardown")
nextitem = None if item.session.shouldfail else nextitem
item.session._setupstate.teardown_exact(nextitem)
_update_current_test_var(item, None) I also added a unittest in
A plugin resetting
I'm not really following this comment, likely just due to my lack of context about the codebase. |
…1721)" Fix pytest-dev#12021. Reopens pytest-dev#11706. This reverts commit 12b9bd5. This change caused a bad regression in pytest-xdist: pytest-dev/pytest-xdist#1024 pytest-xdist necessarily has special handling of `--maxfail` and session fixture teardown get executed multiple times with the change. Since I'm not sure how to adapt pytest-xdist myself, revert for now. I kept the sticky `shouldstop`/`shouldfail` changes as they are good ideas regardless I think.
Reopening since the fix was reverted. |
Let's wait for a pytest-xdist release as there is no rush on the pytest side (there's probably some time until we release 8.2). I think we will do a pytest-xdist release soon (once we tie up so some typing changes there). I will notify you when we can reapply the fix here (unless I forget...). I do foresee we'll get some complaints from users who will be using new pytest with old pytest-xdist, since we can't use dependency constraints to prevent this scenario, but that's OK. |
…1721)" Fix pytest-dev#12021. Reopens pytest-dev#11706. This reverts commit 12b9bd5. This change caused a bad regression in pytest-xdist: pytest-dev/pytest-xdist#1024 pytest-xdist necessarily has special handling of `--maxfail` and session fixture teardown get executed multiple times with the change. Since I'm not sure how to adapt pytest-xdist myself, revert for now. I kept the sticky `shouldstop`/`shouldfail` changes as they are good ideas regardless I think.
@bbrown1867 We has some issues with the 3.6.0 xdist release which had to be yanked, but I released 3.6.1 now and hopefully it'd be fine. So we can proceed on the pytest side. |
Okay sounds good, I'll open a PR to revert 4cc87ad |
…2279) Closes #11706. Originally fixed in #11721, but then reverted in #12022 due to a regression in pytest-xdist. The regression was fixed on the pytest-xdist side in pytest-dev/pytest-xdist#1026.
pip list
from the virtual environment you are usingDescription
Pytest aborts if a session-scoped fixture errors during teardown when (a) one or more test cases fail and (b)
--maxfail=1
is used.When this happens,
test-report.xml
does not contain the teardown fixture error. This is problematic as users may want to also record teardown fixture errors when their test cases fail.Minimal Example
Code
Args
pytest example.py --maxfail=1 --junitxml=test-report.xml
Output
Console:
test-report.xml
:Expected Output
I expect pytest to not abort, and report "1 failed, 1 error, 1 skipped" in both the console and
test-report.xml
when this happens.Environment
OS:
macOS Sonoma 14.1.2
Virtual environment:
The text was updated successfully, but these errors were encountered: