Skip to content

Commit 2a17967

Browse files
committed
Dont' require _testcapi for test_monitoring.py
1 parent a85e73b commit 2a17967

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

Lib/test/test_monitoring.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import test.support
1515
from test.support import import_helper, requires_specialization, script_helper
1616

17-
_testcapi = import_helper.import_module("_testcapi")
1817
_testinternalcapi = import_helper.import_module("_testinternalcapi")
1918

2019
PAIR = (0,1)
@@ -2579,21 +2578,24 @@ def test_monitoring_live_at_shutdown(self):
25792578

25802579

25812580
class TestCApiEventGeneration(MonitoringTestBase, unittest.TestCase):
2581+
_testcapi = import_helper.import_module("_testcapi")
25822582

25832583
class Scope:
25842584
def __init__(self, *args):
25852585
self.args = args
25862586

25872587
def __enter__(self):
2588-
_testcapi.monitoring_enter_scope(*self.args)
2588+
self._testcapi.monitoring_enter_scope(*self.args)
25892589

25902590
def __exit__(self, *args):
2591-
_testcapi.monitoring_exit_scope()
2591+
self._testcapi.monitoring_exit_scope()
2592+
2593+
Scope._testcapi = _testcapi
25922594

25932595
def setUp(self):
25942596
super(TestCApiEventGeneration, self).setUp()
25952597

2596-
capi = _testcapi
2598+
capi = self._testcapi
25972599

25982600
self.codelike = capi.CodeLike(2)
25992601

@@ -2662,7 +2664,7 @@ def __call__(self, *args):
26622664
def test_fire_event(self):
26632665
for expected, event, function, *args in self.cases:
26642666
offset = 0
2665-
self.codelike = _testcapi.CodeLike(1)
2667+
self.codelike = self._testcapi.CodeLike(1)
26662668
with self.subTest(function.__name__):
26672669
args_ = (self.codelike, offset) + tuple(args)
26682670
self.check_event_count(event, function, args_, expected)
@@ -2673,7 +2675,7 @@ def test_missing_exception(self):
26732675
continue
26742676
assert args and isinstance(args[-1], BaseException)
26752677
offset = 0
2676-
self.codelike = _testcapi.CodeLike(1)
2678+
self.codelike = self._testcapi.CodeLike(1)
26772679
with self.subTest(function.__name__):
26782680
args_ = (self.codelike, offset) + tuple(args[:-1]) + (None,)
26792681
evt = int(math.log2(event))
@@ -2683,7 +2685,7 @@ def test_missing_exception(self):
26832685
def test_fire_event_failing_callback(self):
26842686
for expected, event, function, *args in self.cases:
26852687
offset = 0
2686-
self.codelike = _testcapi.CodeLike(1)
2688+
self.codelike = self._testcapi.CodeLike(1)
26872689
with self.subTest(function.__name__):
26882690
args_ = (self.codelike, offset) + tuple(args)
26892691
exc = OSError(42)
@@ -2733,12 +2735,14 @@ def check_disable(self, event, func, args, expected):
27332735
def test_disable_event(self):
27342736
for expected, event, function, *args in self.cases:
27352737
offset = 0
2736-
self.codelike = _testcapi.CodeLike(2)
2738+
self.codelike = self._testcapi.CodeLike(2)
27372739
with self.subTest(function.__name__):
27382740
args_ = (self.codelike, 0) + tuple(args)
27392741
self.check_disable(event, function, args_, expected)
27402742

27412743
def test_enter_scope_two_events(self):
2744+
_testcapi = self._testcapi
2745+
27422746
try:
27432747
yield_counter = CounterWithDisable()
27442748
unwind_counter = CounterWithDisable()

0 commit comments

Comments
 (0)