]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45890: Add tests for tracing try-except-finally blocks (GH-29746)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Tue, 7 Dec 2021 10:50:37 +0000 (10:50 +0000)
committerGitHub <noreply@github.com>
Tue, 7 Dec 2021 10:50:37 +0000 (10:50 +0000)
Lib/test/test_sys_settrace.py
Lib/test/test_trace.py

index b565bef4c442391c8315c522a18374e07b495bbd..15c33a28ff2ac6254a6dfa64140e67e3d277aa11 100644 (file)
@@ -642,15 +642,18 @@ class TraceTestCase(unittest.TestCase):
                 2
             except:
                 4
-            finally:
+            else:
                 6
+            finally:
+                8
 
         self.run_and_compare(func,
             [(0, 'call'),
              (1, 'line'),
              (2, 'line'),
              (6, 'line'),
-             (6, 'return')])
+             (8, 'line'),
+             (8, 'return')])
 
     def test_nested_loops(self):
 
@@ -1016,6 +1019,47 @@ class TraceTestCase(unittest.TestCase):
              (3, 'line'),
              (3, 'return')])
 
+    def test_try_in_try_with_exception(self):
+
+        def func():
+            try:
+                try:
+                    raise TypeError
+                except ValueError as ex:
+                    5
+            except TypeError:
+                7
+
+        self.run_and_compare(func,
+            [(0, 'call'),
+             (1, 'line'),
+             (2, 'line'),
+             (3, 'line'),
+             (3, 'exception'),
+             (4, 'line'),
+             (6, 'line'),
+             (7, 'line'),
+             (7, 'return')])
+
+        def func():
+            try:
+                try:
+                    raise ValueError
+                except ValueError as ex:
+                    5
+            except TypeError:
+                7
+
+        self.run_and_compare(func,
+            [(0, 'call'),
+             (1, 'line'),
+             (2, 'line'),
+             (3, 'line'),
+             (3, 'exception'),
+             (4, 'line'),
+             (5, 'line'),
+             (5, 'return')])
+
     def test_if_in_if_in_if(self):
         def func(a=0, p=1, z=1):
             if p:
index dbfefca7ee5cd67d48af5679e1dd96a44feba2d9..d63c1778c9d0815d9aaa9a9c49ed3614233dd8fc 100644 (file)
@@ -11,6 +11,11 @@ from trace import Trace
 
 from test.tracedmodules import testmod
 
+##
+## See also test_sys_settrace.py, which contains tests that cover
+## tracing of many more code blocks.
+##
+
 #------------------------------- Utilities -----------------------------------#
 
 def fix_ext_py(filename):