Skip to content
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

result: keep original traceback and reraise with it #504

Merged
merged 2 commits into from Apr 30, 2024

Conversation

bluetech
Copy link
Member

The Result API allows the same exception to be raised multiple times. In Python, Exception.__traceback__ becomes longer every time an exception is raised. This means that on every raise, the exception's traceback gets longer and longer.

To prevent this, save the original traceback and always raise using it.

Regressed in pluggy 1.1.0 (fbc4442).

These do nothing, I was just confused.
The `Result` API allows the same exception to be raised multiple times.
In Python, `Exception.__traceback__` becomes longer everytime an
exception is raised. This means that on every raise, the exception's
traceback gets longer and longer.

To prevent this, save the original traceback and always raise using it.

Regressed in pluggy 1.1.0 (fbc4442).
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious as to why the use of dunder exception broke

I recall it worked before

@@ -136,7 +136,7 @@ def _multicall(
_raise_wrapfail(teardown, "has second yield") # type: ignore[arg-type]

if exception is not None:
raise exception.with_traceback(exception.__traceback__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to eventually elevate this to a group in a major release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so.

@bluetech
Copy link
Member Author

I'm curious as to why the use of dunder exception broke
I recall it worked before

The breakage is entirely due to my misunderstanding of how exceptions work. In pluggy it is less impactful than the similar breakage in pytest because there's no potential of thousands of re-raises of the same exception, but wanted to fix it anyway.

@bluetech bluetech merged commit 56085d7 into pytest-dev:main Apr 30, 2024
14 checks passed
@bluetech bluetech deleted the reraise branch April 30, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants