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

Issue #11850 - Add sys.last_exc #11934

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Edison Gustavo Muenz
Edoardo Batini
Edson Tadeu M. Manoel
Eduardo Schettino
Edward Haigh
Eli Boyarski
Elizaveta Shashkova
Éloi Rivard
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
del sys.last_type
del sys.last_value
del sys.last_traceback
if sys.version_info >= (3, 12, 0):
del sys.last_exc

Check warning on line 172 in src/_pytest/runner.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/runner.py#L172

Added line #L172 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

Turns it the type stub for it is just missing from typeshed (the project which provides type annotations for the standard library). I sent a fix for it, but until it's integrated (in a future mypy version), let's add type-ignores for it, like this:

Suggested change
del sys.last_exc
del sys.last_exc # type: ignore[attr-defined]

except AttributeError:
pass
try:
Expand All @@ -176,6 +178,8 @@
# Store trace info to allow postmortem debugging
sys.last_type = type(e)
sys.last_value = e
if sys.version_info >= (3, 12, 0):
sys.last_exc = e

Check warning on line 182 in src/_pytest/runner.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/runner.py#L182

Added line #L182 was not covered by tests
assert e.__traceback__ is not None
# Skip *this* frame
sys.last_traceback = e.__traceback__.tb_next
Expand Down