Add test for exception

This commit is contained in:
Alex Hall 2019-05-11 12:19:51 +02:00 committed by Ram Rachum
parent f6001ce3b1
commit dea100b929
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,49 @@
import pysnooper
def foo():
raise TypeError('bad')
def bar():
try:
foo()
except Exception as e:
str(e)
raise
@pysnooper.snoop(depth=3)
def main():
try:
bar()
except:
pass
expected_output = '''
12:18:08.017782 call 17 def main():
12:18:08.018142 line 18 try:
12:18:08.018181 line 19 bar()
12:18:08.018223 call 8 def bar():
12:18:08.018260 line 9 try:
12:18:08.018293 line 10 foo()
12:18:08.018329 call 4 def foo():
12:18:08.018364 line 5 raise TypeError('bad')
12:18:08.018396 exception 5 raise TypeError('bad')
TypeError: bad
Call ended by exception
12:18:08.018494 exception 10 foo()
TypeError: bad
12:18:08.018545 line 11 except Exception as e:
New var:....... e = TypeError('bad',)
12:18:08.018597 line 12 str(e)
12:18:08.018655 line 13 raise
Call ended by exception
12:18:08.018718 exception 19 bar()
TypeError: bad
12:18:08.018761 line 20 except:
12:18:08.018787 line 21 pass
12:18:08.018813 return 21 pass
Return value:.. None
'''

View file

@ -938,3 +938,8 @@ def test_indentation():
from .samples import indentation, recursion
assert_sample_output(indentation)
assert_sample_output(recursion)
def test_exception():
from .samples import exception
assert_sample_output(exception)