1414import test .support
1515from test .support import import_helper , requires_specialization , script_helper
1616
17- _testcapi = import_helper .import_module ("_testcapi" )
18- _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
19-
2017PAIR = (0 ,1 )
2118
2219def f1 ():
@@ -867,6 +864,8 @@ def test_implicit_stop_iteration(self):
867864 This test checks that both paths record an equivalent event.
868865 """
869866
867+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
868+
870869 def gen ():
871870 yield 1
872871 return 2
@@ -1034,6 +1033,8 @@ def func():
10341033
10351034 @requires_specialization
10361035 def test_no_unwind_for_shim_frame (self ):
1036+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
1037+
10371038 class ValueErrorRaiser :
10381039 def __init__ (self ):
10391040 raise ValueError ()
@@ -2455,6 +2456,7 @@ def run():
24552456 sys .monitoring .set_events (TEST_TOOL , 0 )
24562457
24572458 def test_108390 (self ):
2459+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
24582460
24592461 class Foo :
24602462 def __init__ (self , set_event ):
@@ -2546,6 +2548,8 @@ def test_func(x):
25462548class TestTier2Optimizer (CheckEvents ):
25472549
25482550 def test_monitoring_already_opimized_loop (self ):
2551+ _testinternalcapi = import_helper .import_module ("_testinternalcapi" )
2552+
25492553 def test_func (recorder ):
25502554 set_events = sys .monitoring .set_events
25512555 line = E .LINE
@@ -2582,18 +2586,20 @@ class TestCApiEventGeneration(MonitoringTestBase, unittest.TestCase):
25822586
25832587 class Scope :
25842588 def __init__ (self , * args ):
2589+ self ._testcapi = import_helper .import_module ("_testcapi" )
25852590 self .args = args
25862591
25872592 def __enter__ (self ):
2588- _testcapi .monitoring_enter_scope (* self .args )
2593+ self . _testcapi .monitoring_enter_scope (* self .args )
25892594
25902595 def __exit__ (self , * args ):
2591- _testcapi .monitoring_exit_scope ()
2596+ self . _testcapi .monitoring_exit_scope ()
25922597
25932598 def setUp (self ):
25942599 super (TestCApiEventGeneration , self ).setUp ()
25952600
2596- capi = _testcapi
2601+ self ._testcapi = import_helper .import_module ("_testcapi" )
2602+ capi = self ._testcapi
25972603
25982604 self .codelike = capi .CodeLike (2 )
25992605
@@ -2662,7 +2668,7 @@ def __call__(self, *args):
26622668 def test_fire_event (self ):
26632669 for expected , event , function , * args in self .cases :
26642670 offset = 0
2665- self .codelike = _testcapi .CodeLike (1 )
2671+ self .codelike = self . _testcapi .CodeLike (1 )
26662672 with self .subTest (function .__name__ ):
26672673 args_ = (self .codelike , offset ) + tuple (args )
26682674 self .check_event_count (event , function , args_ , expected )
@@ -2673,7 +2679,7 @@ def test_missing_exception(self):
26732679 continue
26742680 assert args and isinstance (args [- 1 ], BaseException )
26752681 offset = 0
2676- self .codelike = _testcapi .CodeLike (1 )
2682+ self .codelike = self . _testcapi .CodeLike (1 )
26772683 with self .subTest (function .__name__ ):
26782684 args_ = (self .codelike , offset ) + tuple (args [:- 1 ]) + (None ,)
26792685 evt = int (math .log2 (event ))
@@ -2683,7 +2689,7 @@ def test_missing_exception(self):
26832689 def test_fire_event_failing_callback (self ):
26842690 for expected , event , function , * args in self .cases :
26852691 offset = 0
2686- self .codelike = _testcapi .CodeLike (1 )
2692+ self .codelike = self . _testcapi .CodeLike (1 )
26872693 with self .subTest (function .__name__ ):
26882694 args_ = (self .codelike , offset ) + tuple (args )
26892695 exc = OSError (42 )
@@ -2733,12 +2739,14 @@ def check_disable(self, event, func, args, expected):
27332739 def test_disable_event (self ):
27342740 for expected , event , function , * args in self .cases :
27352741 offset = 0
2736- self .codelike = _testcapi .CodeLike (2 )
2742+ self .codelike = self . _testcapi .CodeLike (2 )
27372743 with self .subTest (function .__name__ ):
27382744 args_ = (self .codelike , 0 ) + tuple (args )
27392745 self .check_disable (event , function , args_ , expected )
27402746
27412747 def test_enter_scope_two_events (self ):
2748+ _testcapi = self ._testcapi
2749+
27422750 try :
27432751 yield_counter = CounterWithDisable ()
27442752 unwind_counter = CounterWithDisable ()
0 commit comments