Skip to content

Commit d69805b

Browse files
gh-109156: Add tests for de-instrumenting instructions with instrumented lines (GH-109157)
1 parent a0c06a4 commit d69805b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Lib/test/test_monitoring.py

+17
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,23 @@ def func1():
11521152
('instruction', 'func1', 14),
11531153
('line', 'get_events', 11)])
11541154

1155+
def test_turn_off_only_instruction(self):
1156+
"""
1157+
LINE events should be recorded after INSTRUCTION event is turned off
1158+
"""
1159+
events = []
1160+
def line(*args):
1161+
events.append("line")
1162+
sys.monitoring.set_events(TEST_TOOL, 0)
1163+
sys.monitoring.register_callback(TEST_TOOL, E.LINE, line)
1164+
sys.monitoring.register_callback(TEST_TOOL, E.INSTRUCTION, lambda *args: None)
1165+
sys.monitoring.set_events(TEST_TOOL, E.LINE | E.INSTRUCTION)
1166+
sys.monitoring.set_events(TEST_TOOL, E.LINE)
1167+
events = []
1168+
a = 0
1169+
sys.monitoring.set_events(TEST_TOOL, 0)
1170+
self.assertGreater(len(events), 0)
1171+
11551172
class TestInstallIncrementallly(MonitoringTestBase, unittest.TestCase):
11561173

11571174
def check_events(self, func, must_include, tool=TEST_TOOL, recorders=(ExceptionRecorder,)):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add tests for de-instrumenting instructions while keeping the instrumentation for lines

0 commit comments

Comments
 (0)