summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2024-03-28 08:40:37 (GMT)
committerGitHub <noreply@github.com>2024-03-28 08:40:37 (GMT)
commit6c8ac8a32fd6de1960526561c44bc5603fab0f3e (patch)
tree0887ed16cc1dd81430fe69f671c714c05e3785d9
parent0f27672c5002de96c9f1228b12460d5ce3f1d190 (diff)
downloadcpython-6c8ac8a32fd6de1960526561c44bc5603fab0f3e.zip
cpython-6c8ac8a32fd6de1960526561c44bc5603fab0f3e.tar.gz
cpython-6c8ac8a32fd6de1960526561c44bc5603fab0f3e.tar.bz2
gh-116303: Handle disabled test modules in test.support helpers (#116482)
Make sure test.support helpers skip iso. failing if test extension modules are disabled. Also log TEST_MODULES in test.pythoninfo.
-rw-r--r--Lib/test/pythoninfo.py1
-rw-r--r--Lib/test/support/__init__.py20
-rw-r--r--Lib/test/support/bytecode_helper.py14
3 files changed, 27 insertions, 8 deletions
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index c8bf16d..0cfd033 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -524,6 +524,7 @@ def collect_sysconfig(info_add):
'Py_GIL_DISABLED',
'SHELL',
'SOABI',
+ 'TEST_MODULES',
'abs_builddir',
'abs_srcdir',
'prefix',
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 3d78687..92e3174 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1715,7 +1715,10 @@ def run_in_subinterp(code):
module is enabled.
"""
_check_tracemalloc()
- import _testcapi
+ try:
+ import _testcapi
+ except ImportError:
+ raise unittest.SkipTest("requires _testcapi")
return _testcapi.run_in_subinterp(code)
@@ -1725,7 +1728,10 @@ def run_in_subinterp_with_config(code, *, own_gil=None, **config):
module is enabled.
"""
_check_tracemalloc()
- import _testinternalcapi
+ try:
+ import _testinternalcapi
+ except ImportError:
+ raise unittest.SkipTest("requires _testinternalcapi")
if own_gil is not None:
assert 'gil' not in config, (own_gil, config)
config['gil'] = 2 if own_gil else 1
@@ -1887,12 +1893,18 @@ class SaveSignals:
def with_pymalloc():
- import _testcapi
+ try:
+ import _testcapi
+ except ImportError:
+ raise unittest.SkipTest("requires _testcapi")
return _testcapi.WITH_PYMALLOC and not Py_GIL_DISABLED
def with_mimalloc():
- import _testcapi
+ try:
+ import _testcapi
+ except ImportError:
+ raise unittest.SkipTest("requires _testcapi")
return _testcapi.WITH_MIMALLOC
diff --git a/Lib/test/support/bytecode_helper.py b/Lib/test/support/bytecode_helper.py
index a484506..7a0e884 100644
--- a/Lib/test/support/bytecode_helper.py
+++ b/Lib/test/support/bytecode_helper.py
@@ -3,7 +3,10 @@
import unittest
import dis
import io
-from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object
+try:
+ import _testinternalcapi
+except ImportError:
+ _testinternalcapi = None
_UNSPECIFIED = object()
@@ -133,23 +136,26 @@ class CompilationStepTestCase(unittest.TestCase):
return res
+@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
class CodegenTestCase(CompilationStepTestCase):
def generate_code(self, ast):
- insts, _ = compiler_codegen(ast, "my_file.py", 0)
+ insts, _ = _testinternalcapi.compiler_codegen(ast, "my_file.py", 0)
return insts
+@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
class CfgOptimizationTestCase(CompilationStepTestCase):
def get_optimized(self, insts, consts, nlocals=0):
insts = self.normalize_insts(insts)
insts = self.complete_insts_info(insts)
- insts = optimize_cfg(insts, consts, nlocals)
+ insts = _testinternalcapi.optimize_cfg(insts, consts, nlocals)
return insts, consts
+@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
class AssemblerTestCase(CompilationStepTestCase):
def get_code_object(self, filename, insts, metadata):
- co = assemble_code_object(filename, insts, metadata)
+ co = _testinternalcapi.assemble_code_object(filename, insts, metadata)
return co