https://github.com/python/cpython/commit/3e286f7384c7f08183bd6f76d2adb85e1484cc0b
commit: 3e286f7384c7f08183bd6f76d2adb85e1484cc0b
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-06-30T12:16:15+02:00
summary:
[3.15] Don't require the `_test{internal}capi` modules in `test_monitoring.py`
(GH-152311) (#152660)
(cherry picked from commit 189ab8388762c8102b2d72ad3a1a921f7f2aef10)
Co-authored-by: Shahar Naveh <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
files:
M Lib/test/test_monitoring.py
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index b8861d09e1564b..5c2d69934b02ea 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -14,9 +14,6 @@
import test.support
from test.support import import_helper, requires_specialization, script_helper
-_testcapi = import_helper.import_module("_testcapi")
-_testinternalcapi = import_helper.import_module("_testinternalcapi")
-
PAIR = (0,1)
def f1():
@@ -867,6 +864,8 @@ def test_implicit_stop_iteration(self):
This test checks that both paths record an equivalent event.
"""
+ _testinternalcapi = import_helper.import_module("_testinternalcapi")
+
def gen():
yield 1
return 2
@@ -1034,6 +1033,8 @@ def func():
@requires_specialization
def test_no_unwind_for_shim_frame(self):
+ _testinternalcapi = import_helper.import_module("_testinternalcapi")
+
class ValueErrorRaiser:
def __init__(self):
raise ValueError()
@@ -2455,6 +2456,7 @@ def run():
sys.monitoring.set_events(TEST_TOOL, 0)
def test_108390(self):
+ _testinternalcapi = import_helper.import_module("_testinternalcapi")
class Foo:
def __init__(self, set_event):
@@ -2546,6 +2548,8 @@ def test_func(x):
class TestTier2Optimizer(CheckEvents):
def test_monitoring_already_opimized_loop(self):
+ _testinternalcapi = import_helper.import_module("_testinternalcapi")
+
def test_func(recorder):
set_events = sys.monitoring.set_events
line = E.LINE
@@ -2582,18 +2586,20 @@ class TestCApiEventGeneration(MonitoringTestBase,
unittest.TestCase):
class Scope:
def __init__(self, *args):
+ self._testcapi = import_helper.import_module("_testcapi")
self.args = args
def __enter__(self):
- _testcapi.monitoring_enter_scope(*self.args)
+ self._testcapi.monitoring_enter_scope(*self.args)
def __exit__(self, *args):
- _testcapi.monitoring_exit_scope()
+ self._testcapi.monitoring_exit_scope()
def setUp(self):
super(TestCApiEventGeneration, self).setUp()
- capi = _testcapi
+ self._testcapi = import_helper.import_module("_testcapi")
+ capi = self._testcapi
self.codelike = capi.CodeLike(2)
@@ -2662,7 +2668,7 @@ def __call__(self, *args):
def test_fire_event(self):
for expected, event, function, *args in self.cases:
offset = 0
- self.codelike = _testcapi.CodeLike(1)
+ self.codelike = self._testcapi.CodeLike(1)
with self.subTest(function.__name__):
args_ = (self.codelike, offset) + tuple(args)
self.check_event_count(event, function, args_, expected)
@@ -2673,7 +2679,7 @@ def test_missing_exception(self):
continue
assert args and isinstance(args[-1], BaseException)
offset = 0
- self.codelike = _testcapi.CodeLike(1)
+ self.codelike = self._testcapi.CodeLike(1)
with self.subTest(function.__name__):
args_ = (self.codelike, offset) + tuple(args[:-1]) + (None,)
evt = int(math.log2(event))
@@ -2683,7 +2689,7 @@ def test_missing_exception(self):
def test_fire_event_failing_callback(self):
for expected, event, function, *args in self.cases:
offset = 0
- self.codelike = _testcapi.CodeLike(1)
+ self.codelike = self._testcapi.CodeLike(1)
with self.subTest(function.__name__):
args_ = (self.codelike, offset) + tuple(args)
exc = OSError(42)
@@ -2733,12 +2739,14 @@ def check_disable(self, event, func, args, expected):
def test_disable_event(self):
for expected, event, function, *args in self.cases:
offset = 0
- self.codelike = _testcapi.CodeLike(2)
+ self.codelike = self._testcapi.CodeLike(2)
with self.subTest(function.__name__):
args_ = (self.codelike, 0) + tuple(args)
self.check_disable(event, function, args_, expected)
def test_enter_scope_two_events(self):
+ _testcapi = self._testcapi
+
try:
yield_counter = CounterWithDisable()
unwind_counter = CounterWithDisable()
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]