1414import test .support
1515from test .support import import_helper , requires_specialization_ft , script_helper
1616
17- _testcapi = import_helper .import_module ("_testcapi" )
18- _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
19-
2017PAIR = (0 ,1 )
2118
2219def f1 ():
@@ -882,6 +879,8 @@ def test_implicit_stop_iteration(self):
882879 This test checks that both paths record an equivalent event.
883880 """
884881
882+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
883+
885884 def gen ():
886885 yield 1
887886 return 2
@@ -1049,6 +1048,8 @@ def func():
10491048
10501049 @requires_specialization_ft
10511050 def test_no_unwind_for_shim_frame (self ):
1051+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
1052+
10521053 class ValueErrorRaiser :
10531054 def __init__ (self ):
10541055 raise ValueError ()
@@ -2141,6 +2142,7 @@ def run():
21412142 sys .monitoring .set_events (TEST_TOOL , 0 )
21422143
21432144 def test_108390 (self ):
2145+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
21442146
21452147 class Foo :
21462148 def __init__ (self , set_event ):
@@ -2217,6 +2219,8 @@ def test_func(x):
22172219class TestTier2Optimizer (CheckEvents ):
22182220
22192221 def test_monitoring_already_opimized_loop (self ):
2222+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
2223+
22202224 def test_func (recorder ):
22212225 set_events = sys .monitoring .set_events
22222226 line = E .LINE
@@ -2253,18 +2257,20 @@ class TestCApiEventGeneration(MonitoringTestBase, unittest.TestCase):
22532257
22542258 class Scope :
22552259 def __init__ (self , * args ):
2260+ self ._testcapi = import_helper .import_module ("_testcapi" )
22562261 self .args = args
22572262
22582263 def __enter__ (self ):
2259- _testcapi .monitoring_enter_scope (* self .args )
2264+ self . _testcapi .monitoring_enter_scope (* self .args )
22602265
22612266 def __exit__ (self , * args ):
2262- _testcapi .monitoring_exit_scope ()
2267+ self . _testcapi .monitoring_exit_scope ()
22632268
22642269 def setUp (self ):
22652270 super (TestCApiEventGeneration , self ).setUp ()
22662271
2267- capi = _testcapi
2272+ self ._testcapi = import_helper .import_module ("_testcapi" )
2273+ capi = self ._testcapi
22682274
22692275 self .codelike = capi .CodeLike (2 )
22702276
@@ -2333,7 +2339,7 @@ def __call__(self, *args):
23332339 def test_fire_event (self ):
23342340 for expected , event , function , * args in self .cases :
23352341 offset = 0
2336- self .codelike = _testcapi .CodeLike (1 )
2342+ self .codelike = self . _testcapi .CodeLike (1 )
23372343 with self .subTest (function .__name__ ):
23382344 args_ = (self .codelike , offset ) + tuple (args )
23392345 self .check_event_count (event , function , args_ , expected )
@@ -2344,7 +2350,7 @@ def test_missing_exception(self):
23442350 continue
23452351 assert args and isinstance (args [- 1 ], BaseException )
23462352 offset = 0
2347- self .codelike = _testcapi .CodeLike (1 )
2353+ self .codelike = self . _testcapi .CodeLike (1 )
23482354 with self .subTest (function .__name__ ):
23492355 args_ = (self .codelike , offset ) + tuple (args [:- 1 ]) + (None ,)
23502356 evt = int (math .log2 (event ))
@@ -2354,7 +2360,7 @@ def test_missing_exception(self):
23542360 def test_fire_event_failing_callback (self ):
23552361 for expected , event , function , * args in self .cases :
23562362 offset = 0
2357- self .codelike = _testcapi .CodeLike (1 )
2363+ self .codelike = self . _testcapi .CodeLike (1 )
23582364 with self .subTest (function .__name__ ):
23592365 args_ = (self .codelike , offset ) + tuple (args )
23602366 exc = OSError (42 )
@@ -2404,12 +2410,14 @@ def check_disable(self, event, func, args, expected):
24042410 def test_disable_event (self ):
24052411 for expected , event , function , * args in self .cases :
24062412 offset = 0
2407- self .codelike = _testcapi .CodeLike (2 )
2413+ self .codelike = self . _testcapi .CodeLike (2 )
24082414 with self .subTest (function .__name__ ):
24092415 args_ = (self .codelike , 0 ) + tuple (args )
24102416 self .check_disable (event , function , args_ , expected )
24112417
24122418 def test_enter_scope_two_events (self ):
2419+ _testcapi = self ._testcapi
2420+
24132421 try :
24142422 yield_counter = CounterWithDisable ()
24152423 unwind_counter = CounterWithDisable ()
0 commit comments