Skip to content

Commit 2e4db16

Browse files
committed
add test
1 parent e8b3ec8 commit 2e4db16

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/test/test_monitoring.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,24 @@ def func(v=1):
17091709
('branch right', 'func', 6, 8),
17101710
('branch right', 'func', 2, 10)])
17111711

1712+
def test_callback_set_frame_lineno(self):
1713+
def func(s: str) -> int:
1714+
if s.startswith("t"):
1715+
return 1
1716+
else:
1717+
return 0
1718+
1719+
def callback(code, from_, to):
1720+
frame = sys._getframe(0)
1721+
old = frame.f_lineno
1722+
# try set frame.f_lineno
1723+
frame.f_lineno = frame.f_lineno
1724+
1725+
sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
1726+
sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)
1727+
1728+
self.assertEqual(func("true"), 1)
1729+
17121730

17131731
class TestBranchConsistency(MonitoringTestBase, unittest.TestCase):
17141732

0 commit comments

Comments
 (0)