"git@developer.sourcefind.cn:OpenDAS/lmdeploy.git" did not exist on "7f943a26b69b1e8f80aecb0a660b15eb5719b7b5"
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): ...@@ -210,7 +210,7 @@ def cache(fn):
""" """
sentinel = object() sentinel = object()
out_cache = {} out_cache = {}
exc_cache = {} exc_tb_cache = {}
@functools.wraps(fn) @functools.wraps(fn)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
...@@ -220,14 +220,17 @@ def cache(fn): ...@@ -220,14 +220,17 @@ def cache(fn):
if out is not sentinel: if out is not sentinel:
return out return out
exc = exc_cache.get(key, sentinel) exc_tb = exc_tb_cache.get(key, sentinel)
if exc is not sentinel: if exc_tb is not sentinel:
raise exc raise exc_tb[0].with_traceback(exc_tb[1])
try: try:
out = fn(*args, **kwargs) out = fn(*args, **kwargs)
except Exception as exc: 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 raise exc
out_cache[key] = out 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