summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_import
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2024-04-03 13:11:36 (GMT)
committerGitHub <noreply@github.com>2024-04-03 13:11:36 (GMT)
commitea94b3b149eeadf33c2f7c46f16dcda0adc7cf4e (patch)
tree7fc58f8dcd7513427c7ea2ff9d7bad523be1118a /Lib/test/test_import
parent2ec6bb4111d2c03c1cac02b27c74beee7e5a2a05 (diff)
downloadcpython-ea94b3b149eeadf33c2f7c46f16dcda0adc7cf4e.zip
cpython-ea94b3b149eeadf33c2f7c46f16dcda0adc7cf4e.tar.gz
cpython-ea94b3b149eeadf33c2f7c46f16dcda0adc7cf4e.tar.bz2
gh-116303: Skip test module dependent tests if test modules are unavailable (#117341)
Diffstat (limited to 'Lib/test/test_import')
-rw-r--r--Lib/test/test_import/__init__.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 3c387d9..6678548 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -33,7 +33,7 @@ from test.support import (
is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, ready_to_import,
- DirsOnSysPath, CleanImport)
+ DirsOnSysPath, CleanImport, import_module)
from test.support.os_helper import (
TESTFN, rmtree, temp_umask, TESTFN_UNENCODABLE)
from test.support import script_helper
@@ -363,7 +363,7 @@ class ImportTests(unittest.TestCase):
@cpython_only
def test_from_import_missing_attr_has_name_and_so_path(self):
- import _testcapi
+ _testcapi = import_module("_testcapi")
with self.assertRaises(ImportError) as cm:
from _testcapi import i_dont_exist
self.assertEqual(cm.exception.name, '_testcapi')
@@ -1870,6 +1870,7 @@ class SubinterpImportTests(unittest.TestCase):
f'ImportError: module {name} does not support loading in subinterpreters',
)
+ @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_builtin_compat(self):
# For now we avoid using sys or builtins
# since they still don't implement multi-phase init.
@@ -1881,6 +1882,7 @@ class SubinterpImportTests(unittest.TestCase):
self.check_compatible_here(module, strict=True)
@cpython_only
+ @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_frozen_compat(self):
module = '_frozen_importlib'
require_frozen(module, skip=True)
@@ -1951,6 +1953,7 @@ class SubinterpImportTests(unittest.TestCase):
self.check_compatible_here(modname, filename,
strict=False, isolated=False)
+ @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_python_compat(self):
module = 'threading'
require_pure_python(module)
@@ -1996,6 +1999,7 @@ class SubinterpImportTests(unittest.TestCase):
with self.subTest('config: check disabled; override: disabled'):
check_compatible(False, -1)
+ @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_isolated_config(self):
module = 'threading'
require_pure_python(module)
@@ -2741,7 +2745,7 @@ class CAPITests(unittest.TestCase):
def test_pyimport_addmodule(self):
# gh-105922: Test PyImport_AddModuleRef(), PyImport_AddModule()
# and PyImport_AddModuleObject()
- import _testcapi
+ _testcapi = import_module("_testcapi")
for name in (
'sys', # frozen module
'test', # package
@@ -2751,7 +2755,7 @@ class CAPITests(unittest.TestCase):
def test_pyimport_addmodule_create(self):
# gh-105922: Test PyImport_AddModuleRef(), create a new module
- import _testcapi
+ _testcapi = import_module("_testcapi")
name = 'dontexist'
self.assertNotIn(name, sys.modules)
self.addCleanup(unload, name)