Unverified Commit 0bfbabc2 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

cache traceback together with exceptions (#6748)

parent 11a2eeda
......@@ -210,7 +210,7 @@ def cache(fn):
"""
sentinel = object()
out_cache = {}
exc_cache = {}
exc_tb_cache = {}
@functools.wraps(fn)
def wrapper(*args, **kwargs):
......@@ -220,14 +220,17 @@ def cache(fn):
if out is not sentinel:
return out
exc = exc_cache.get(key, sentinel)
if exc is not sentinel:
raise exc
exc_tb = exc_tb_cache.get(key, sentinel)
if exc_tb is not sentinel:
raise exc_tb[0].with_traceback(exc_tb[1])
try:
out = fn(*args, **kwargs)
except Exception as exc:
exc_cache[key] = exc
# We need to cache the traceback here as well. Otherwise, each re-raise will add the internal pytest
# traceback frames anew, but they will only be removed once. Thus, the traceback will be ginormous hiding
# the actual information in the noise. See https://github.com/pytest-dev/pytest/issues/10363 for details.
exc_tb_cache[key] = exc, exc.__traceback__
raise exc
out_cache[key] = out
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment