-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
result: keep original traceback and reraise with it
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).
- Loading branch information
Showing
3 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a regression in pluggy 1.1.0 where using :func:`result.get_result() <pluggy.Result.get_result>` on the same failed :class:`~pluggy.Result` causes the exception's traceback to get longer and longer. |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import traceback | ||
|
||
from pluggy import Result | ||
|
||
|
||
def test_exceptions_traceback_doesnt_get_longer_and_longer() -> None: | ||
def bad() -> None: | ||
1 / 0 | ||
|
||
result = Result.from_call(bad) | ||
|
||
try: | ||
result.get_result() | ||
except Exception as exc: | ||
tb1 = traceback.extract_tb(exc.__traceback__) | ||
|
||
try: | ||
result.get_result() | ||
except Exception as exc: | ||
tb2 = traceback.extract_tb(exc.__traceback__) | ||
|
||
try: | ||
result.get_result() | ||
except Exception as exc: | ||
tb3 = traceback.extract_tb(exc.__traceback__) | ||
|
||
assert len(tb1) == len(tb2) == len(tb3) |