Fix '_thread._local' object has no attribute 'depth' raised by snooper if there's exception upon calling snooped func by initializing thread_global dict with depth when entering the trace() func
This commit is contained in:
Yael Mintz 2020-09-13 15:33:51 +03:00 committed by Ram Rachum
parent 2f80c0f11a
commit f1194be092
2 changed files with 7 additions and 2 deletions

View file

@ -293,6 +293,7 @@ class Tracer:
def __enter__(self):
if DISABLED:
return
thread_global.__dict__.setdefault('depth', -1)
calling_frame = inspect.currentframe().f_back
if not self._is_internal_frame(calling_frame):
calling_frame.f_trace = self.trace
@ -362,7 +363,6 @@ class Tracer:
else:
return None
thread_global.__dict__.setdefault('depth', -1)
if event == 'call':
thread_global.depth += 1
indent = ' ' * 4 * thread_global.depth

View file

@ -1894,5 +1894,10 @@ def test_exception():
)
def test_exception_on_entry():
@pysnooper.snoop()
def f(x):
pass
with pytest.raises(TypeError):
f()