gh-109721: Guard _testinternalcapi imports in tests (GH-109722)

This commit is contained in:
Nikita Sobolev 2023-09-22 23:51:58 +03:00 committed by GitHub
parent 8a82bff12c
commit 8ded34a1ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -799,6 +799,7 @@ def check_pythonmalloc(self, env_var, name):
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()

View file

@ -22,7 +22,6 @@
import types
import unittest
from unittest import mock
import _testinternalcapi
import _imp
from test.support import os_helper
@ -50,6 +49,10 @@
import _xxsubinterpreters as _interpreters
except ModuleNotFoundError:
_interpreters = None
try:
import _testinternalcapi
except ImportError:
_testinternalcapi = None
skip_if_dont_write_bytecode = unittest.skipIf(

View file

@ -4,13 +4,17 @@
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: