-
-
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
fixtures,runner: fix tracebacks getting longer and longer #12264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Fix a regression in pytest 8.0 where tracebacks get longer and longer when multiple tests fail due to a shared higher-scope fixture which raised. | ||
|
||
Also fix a similar regression in pytest 5.4 for collectors which raise during setup. | ||
|
||
The fix necessitated internal changes which may affect some plugins: | ||
- ``FixtureDef.cached_result[2]`` is now a tuple ``(exc, tb)`` instead of ``exc``. | ||
- ``SetupState.stack`` failures are now a tuple ``(exc, tb)`` instead of ``exc``. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import os | ||
from pathlib import Path | ||
import sys | ||
import types | ||
from typing import AbstractSet | ||
from typing import Any | ||
from typing import Callable | ||
|
@@ -104,8 +105,8 @@ | |
None, | ||
# Cache key. | ||
object, | ||
# Exception if raised. | ||
BaseException, | ||
# The exception and the original traceback. | ||
Tuple[BaseException, Optional[types.TracebackType]], | ||
], | ||
] | ||
|
||
|
@@ -1049,8 +1050,8 @@ | |
# numpy arrays (#6497). | ||
if my_cache_key is cache_key: | ||
if self.cached_result[2] is not None: | ||
exc = self.cached_result[2] | ||
raise exc | ||
exc, exc_tb = self.cached_result[2] | ||
raise exc.with_traceback(exc_tb) | ||
else: | ||
result = self.cached_result[0] | ||
return result | ||
|
@@ -1126,7 +1127,7 @@ | |
# Don't show the fixture as the skip location, as then the user | ||
# wouldn't know which test skipped. | ||
e._use_item_location = True | ||
fixturedef.cached_result = (None, my_cache_key, e) | ||
fixturedef.cached_result = (None, my_cache_key, (e, e.__traceback__)) | ||
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. Would it be possible to just pass the dunder traceback into the method to avoid tracking the concrete one for reraise? 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. I don't think so, the exception is saved on the |
||
raise | ||
fixturedef.cached_result = (result, my_cache_key, None) | ||
return result | ||
|
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.
@bluetech FYI this list seems to need indentation or something like that. See the preview of how it's rendered: https://docs.pytest.org/en/latest/changelog.html#bug-fixes.
P.S. I integrated my changelog draft preview Sphinx extension during the sprint. So now, you're going to be able to preview the rendering in new pull requests, even before merging.
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.
I submitted a fix via #12563. It's better with that patch: https://pytest--12563.org.readthedocs.build/en/12563/changelog.html#bug-fixes.