]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109156: Add tests for de-instrumenting instructions with instrumented lines (GH...
authorTian Gao <gaogaotiantian@hotmail.com>
Wed, 13 Sep 2023 08:47:35 +0000 (01:47 -0700)
committerGitHub <noreply@github.com>
Wed, 13 Sep 2023 08:47:35 +0000 (09:47 +0100)
Lib/test/test_monitoring.py
Misc/NEWS.d/next/Core and Builtins/2023-09-08-18-31-04.gh-issue-109156.KK1EXI.rst [new file with mode: 0644]

index 575862b13d7f99fa3f650cc9f12637b55920a94c..992d3cc8b6d7f9b707012c63b83cdd8619a1b8a0 100644 (file)
@@ -1152,6 +1152,23 @@ class TestLineAndInstructionEvents(CheckEvents):
             ('instruction', 'func1', 14),
             ('line', 'get_events', 11)])
 
+    def test_turn_off_only_instruction(self):
+        """
+        LINE events should be recorded after INSTRUCTION event is turned off
+        """
+        events = []
+        def line(*args):
+            events.append("line")
+        sys.monitoring.set_events(TEST_TOOL, 0)
+        sys.monitoring.register_callback(TEST_TOOL, E.LINE, line)
+        sys.monitoring.register_callback(TEST_TOOL, E.INSTRUCTION, lambda *args: None)
+        sys.monitoring.set_events(TEST_TOOL, E.LINE | E.INSTRUCTION)
+        sys.monitoring.set_events(TEST_TOOL, E.LINE)
+        events = []
+        a = 0
+        sys.monitoring.set_events(TEST_TOOL, 0)
+        self.assertGreater(len(events), 0)
+
 class TestInstallIncrementallly(MonitoringTestBase, unittest.TestCase):
 
     def check_events(self, func, must_include, tool=TEST_TOOL, recorders=(ExceptionRecorder,)):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-09-08-18-31-04.gh-issue-109156.KK1EXI.rst b/Misc/NEWS.d/next/Core and Builtins/2023-09-08-18-31-04.gh-issue-109156.KK1EXI.rst
new file mode 100644 (file)
index 0000000..e681482
--- /dev/null
@@ -0,0 +1 @@
+Add tests for de-instrumenting instructions while keeping the instrumentation for lines