Add if statement to only use sys.last_exc in versions >= 3.12.0

This commit is contained in:
robotherapist 2024-02-05 21:18:41 +01:00
parent 358d842642
commit 5171b5df7d
2 changed files with 5 additions and 2 deletions

View File

@ -127,6 +127,7 @@ Edison Gustavo Muenz
Edoardo Batini Edoardo Batini
Edson Tadeu M. Manoel Edson Tadeu M. Manoel
Eduardo Schettino Eduardo Schettino
Edward Haigh
Eli Boyarski Eli Boyarski
Elizaveta Shashkova Elizaveta Shashkova
Éloi Rivard Éloi Rivard

View File

@ -168,7 +168,8 @@ def pytest_runtest_call(item: Item) -> None:
del sys.last_type del sys.last_type
del sys.last_value del sys.last_value
del sys.last_traceback del sys.last_traceback
del sys.last_exc if sys.version_info >= (3,12,0):
del sys.last_exc
except AttributeError: except AttributeError:
pass pass
try: try:
@ -177,7 +178,8 @@ def pytest_runtest_call(item: Item) -> None:
# Store trace info to allow postmortem debugging # Store trace info to allow postmortem debugging
sys.last_type = type(e) sys.last_type = type(e)
sys.last_value = e sys.last_value = e
sys.last_exc = e if sys.version_info >= (3,12,0):
sys.last_exc = e
assert e.__traceback__ is not None assert e.__traceback__ is not None
# Skip *this* frame # Skip *this* frame
sys.last_traceback = e.__traceback__.tb_next sys.last_traceback = e.__traceback__.tb_next