Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Dont' require _testcapi for test_monitoring.py
  • Loading branch information
ShaharNaveh committed Jun 26, 2026
commit 2a17967d44fbf7cb590242739330a688f76b4959
20 changes: 12 additions & 8 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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)
Expand Down Expand Up @@ -2579,21 +2578,24 @@ def test_monitoring_live_at_shutdown(self):


class TestCApiEventGeneration(MonitoringTestBase, unittest.TestCase):
_testcapi = import_helper.import_module("_testcapi")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll be executed at import time, so it will skip test_monitoring defeating the whole point of this PR. You can move it to a setUpClass.


class Scope:
def __init__(self, *args):
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()

Scope._testcapi = _testcapi

def setUp(self):
super(TestCApiEventGeneration, self).setUp()

capi = _testcapi
capi = self._testcapi

self.codelike = capi.CodeLike(2)

Expand Down Expand Up @@ -2662,7 +2664,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)
Expand All @@ -2673,7 +2675,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))
Expand All @@ -2683,7 +2685,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)
Expand Down Expand Up @@ -2733,12 +2735,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()
Expand Down