]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109721: Guard `_testinternalcapi` imports in tests (GH-109722)
authorNikita Sobolev <mail@sobolevn.me>
Fri, 22 Sep 2023 20:51:58 +0000 (23:51 +0300)
committerGitHub <noreply@github.com>
Fri, 22 Sep 2023 20:51:58 +0000 (13:51 -0700)
Lib/test/test_cmd_line.py
Lib/test/test_import/__init__.py
Lib/test/test_opcache.py

index e88b7c8572d9e8bf27aaefdd421a9c423691fe27..f4754dbf735a1d9fbf2cceac817d3ef3169a8b5e 100644 (file)
@@ -799,6 +799,7 @@ class CmdLineTest(unittest.TestCase):
         self.assertEqual(proc.stdout.rstrip(), name)
         self.assertEqual(proc.returncode, 0)
 
+    @support.cpython_only
     def test_pythonmalloc(self):
         # Test the PYTHONMALLOC environment variable
         pymalloc = support.with_pymalloc()
index a302a6075eca0a3d0d0441f380b6683baa505f34..48553f9d48b01033f919a9ab64248727ec0e4364 100644 (file)
@@ -22,7 +22,6 @@ import time
 import types
 import unittest
 from unittest import mock
-import _testinternalcapi
 import _imp
 
 from test.support import os_helper
@@ -50,6 +49,10 @@ try:
     import _xxsubinterpreters as _interpreters
 except ModuleNotFoundError:
     _interpreters = None
+try:
+    import _testinternalcapi
+except ImportError:
+    _testinternalcapi = None
 
 
 skip_if_dont_write_bytecode = unittest.skipIf(
index 692e03fbb5e0841b2c57b2112029a0bdd6b2f3e9..2b2783d57be8f41146c0e9270253640940633ede 100644 (file)
@@ -4,13 +4,17 @@ import dis
 import threading
 import types
 import unittest
-from test.support import threading_helper
+from test.support import threading_helper, check_impl_detail
+
+# Skip this module on other interpreters, it is cpython specific:
+if check_impl_detail(cpython=False):
+    raise unittest.SkipTest('implementation detail specific to cpython')
+
 import _testinternalcapi
 
 
 def disabling_optimizer(func):
     def wrapper(*args, **kwargs):
-        import _testinternalcapi
         old_opt = _testinternalcapi.get_optimizer()
         _testinternalcapi.set_optimizer(None)
         try: