From dea100b9290fb2d88cce3d7c0bfb14d625b5a7b2 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Sat, 11 May 2019 12:19:51 +0200 Subject: [PATCH] Add test for exception --- tests/samples/exception.py | 49 ++++++++++++++++++++++++++++++++++++++ tests/test_pysnooper.py | 5 ++++ 2 files changed, 54 insertions(+) create mode 100644 tests/samples/exception.py diff --git a/tests/samples/exception.py b/tests/samples/exception.py new file mode 100644 index 0000000..bf90979 --- /dev/null +++ b/tests/samples/exception.py @@ -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 +''' diff --git a/tests/test_pysnooper.py b/tests/test_pysnooper.py index 5f266c4..18f27ca 100644 --- a/tests/test_pysnooper.py +++ b/tests/test_pysnooper.py @@ -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)