Skip to content

Commit b8e9f12

Browse files
committed
fix test
1 parent d41cf78 commit b8e9f12

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/test/test_monitoring.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import collections
44
import dis
55
import functools
6+
import inspect
67
import math
78
import operator
89
import sys
@@ -1717,10 +1718,13 @@ def func(s: str) -> int:
17171718
return 0
17181719

17191720
def callback(code, from_, to):
1720-
frame = sys._getframe(0)
1721-
old = frame.f_lineno
17221721
# try set frame.f_lineno
1723-
frame.f_lineno = frame.f_lineno
1722+
frame = inspect.currentframe()
1723+
while frame and frame.f_code is not code:
1724+
frame = frame.f_back
1725+
1726+
self.assertIsNotNone(frame)
1727+
frame.f_lineno = frame.f_lineno + 1 # run next instruction
17241728

17251729
sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
17261730
sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)

0 commit comments

Comments
 (0)