Mailing List Archive

bpo-45890: Add tests for tracing try-except-finally blocks (GH-29746)
https://github.com/python/cpython/commit/a310fd83a014484b8c680de83540c4908b344c6c
commit: a310fd83a014484b8c680de83540c4908b344c6c
branch: main
author: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
committer: markshannon <mark@hotpy.org>
date: 2021-12-07T10:50:37Z
summary:

bpo-45890: Add tests for tracing try-except-finally blocks (GH-29746)

files:
M Lib/test/test_sys_settrace.py
M Lib/test/test_trace.py

diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index b565bef4c4423..15c33a28ff2ac 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -642,15 +642,18 @@ def func():
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 @@ def func():
(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:
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index dbfefca7ee5cd..d63c1778c9d08 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -11,6 +11,11 @@

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):

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins