pytest-dev / pluggy

A minimalist production ready plugin system
https://pluggy.readthedocs.io/en/latest/
MIT License
1.23k stars 121 forks source link

result: keep original traceback and reraise with it #504

Closed bluetech closed 3 months ago

bluetech commented 3 months ago

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).

bluetech commented 3 months ago

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.