Skip to content

gh-109721: Guard _testinternalcapi imports in tests #109722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import types
import unittest
from unittest import mock
import _testinternalcapi
import _imp

from test.support import os_helper
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down