Skip to content

Commit

Permalink
pythongh-109721: Guard _testinernalcapi imports in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 22, 2023
1 parent 34ddcc3 commit 778e504
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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
7 changes: 4 additions & 3 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import threading
import types
import unittest
from test.support import threading_helper
import _testinternalcapi
from test.support import threading_helper, import_helper

# Skip this module on other interpreters, it is cpython specific:
_testinternalcapi = import_helper.import_module('_testinternalcapi')


def disabling_optimizer(func):
def wrapper(*args, **kwargs):
import _testinternalcapi
old_opt = _testinternalcapi.get_optimizer()
_testinternalcapi.set_optimizer(None)
try:
Expand Down

0 comments on commit 778e504

Please sign in to comment.