Skip to content

Commit 8ded34a

Browse files
authored
gh-109721: Guard _testinternalcapi imports in tests (GH-109722)
1 parent 8a82bff commit 8ded34a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Lib/test/test_cmd_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ def check_pythonmalloc(self, env_var, name):
799799
self.assertEqual(proc.stdout.rstrip(), name)
800800
self.assertEqual(proc.returncode, 0)
801801

802+
@support.cpython_only
802803
def test_pythonmalloc(self):
803804
# Test the PYTHONMALLOC environment variable
804805
pymalloc = support.with_pymalloc()

Lib/test/test_import/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import types
2323
import unittest
2424
from unittest import mock
25-
import _testinternalcapi
2625
import _imp
2726

2827
from test.support import os_helper
@@ -50,6 +49,10 @@
5049
import _xxsubinterpreters as _interpreters
5150
except ModuleNotFoundError:
5251
_interpreters = None
52+
try:
53+
import _testinternalcapi
54+
except ImportError:
55+
_testinternalcapi = None
5356

5457

5558
skip_if_dont_write_bytecode = unittest.skipIf(

Lib/test/test_opcache.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
import threading
55
import types
66
import unittest
7-
from test.support import threading_helper
7+
from test.support import threading_helper, check_impl_detail
8+
9+
# Skip this module on other interpreters, it is cpython specific:
10+
if check_impl_detail(cpython=False):
11+
raise unittest.SkipTest('implementation detail specific to cpython')
12+
813
import _testinternalcapi
914

1015

1116
def disabling_optimizer(func):
1217
def wrapper(*args, **kwargs):
13-
import _testinternalcapi
1418
old_opt = _testinternalcapi.get_optimizer()
1519
_testinternalcapi.set_optimizer(None)
1620
try:

0 commit comments

Comments
 (0)