We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d41cf78 commit b8e9f12Copy full SHA for b8e9f12
1 file changed
Lib/test/test_monitoring.py
@@ -3,6 +3,7 @@
3
import collections
4
import dis
5
import functools
6
+import inspect
7
import math
8
import operator
9
import sys
@@ -1717,10 +1718,13 @@ def func(s: str) -> int:
1717
1718
return 0
1719
1720
def callback(code, from_, to):
- frame = sys._getframe(0)
1721
- old = frame.f_lineno
1722
# try set frame.f_lineno
1723
- frame.f_lineno = frame.f_lineno
+ frame = inspect.currentframe()
+ 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
1728
1729
sys.monitoring.set_local_events(TEST_TOOL, func.__code__, E.BRANCH_LEFT)
1730
sys.monitoring.register_callback(TEST_TOOL, E.BRANCH_LEFT, callback)
0 commit comments