Skip to content

Commit 1333440

Browse files
erlend-aaslandpull[bot]
authored andcommitted
pythongh-116303: Handle disabled test modules in test.support helpers (python#116482)
Make sure test.support helpers skip iso. failing if test extension modules are disabled. Also log TEST_MODULES in test.pythoninfo.
1 parent de729fc commit 1333440

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Lib/test/pythoninfo.py

+1
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ def collect_sysconfig(info_add):
524524
'Py_GIL_DISABLED',
525525
'SHELL',
526526
'SOABI',
527+
'TEST_MODULES',
527528
'abs_builddir',
528529
'abs_srcdir',
529530
'prefix',

Lib/test/support/__init__.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,10 @@ def run_in_subinterp(code):
17151715
module is enabled.
17161716
"""
17171717
_check_tracemalloc()
1718-
import _testcapi
1718+
try:
1719+
import _testcapi
1720+
except ImportError:
1721+
raise unittest.SkipTest("requires _testcapi")
17191722
return _testcapi.run_in_subinterp(code)
17201723

17211724

@@ -1725,7 +1728,10 @@ def run_in_subinterp_with_config(code, *, own_gil=None, **config):
17251728
module is enabled.
17261729
"""
17271730
_check_tracemalloc()
1728-
import _testinternalcapi
1731+
try:
1732+
import _testinternalcapi
1733+
except ImportError:
1734+
raise unittest.SkipTest("requires _testinternalcapi")
17291735
if own_gil is not None:
17301736
assert 'gil' not in config, (own_gil, config)
17311737
config['gil'] = 2 if own_gil else 1
@@ -1887,12 +1893,18 @@ def restore(self):
18871893

18881894

18891895
def with_pymalloc():
1890-
import _testcapi
1896+
try:
1897+
import _testcapi
1898+
except ImportError:
1899+
raise unittest.SkipTest("requires _testcapi")
18911900
return _testcapi.WITH_PYMALLOC and not Py_GIL_DISABLED
18921901

18931902

18941903
def with_mimalloc():
1895-
import _testcapi
1904+
try:
1905+
import _testcapi
1906+
except ImportError:
1907+
raise unittest.SkipTest("requires _testcapi")
18961908
return _testcapi.WITH_MIMALLOC
18971909

18981910

Lib/test/support/bytecode_helper.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import unittest
44
import dis
55
import io
6-
from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object
6+
try:
7+
import _testinternalcapi
8+
except ImportError:
9+
_testinternalcapi = None
710

811
_UNSPECIFIED = object()
912

@@ -133,23 +136,26 @@ def complete_insts_info(self, insts):
133136
return res
134137

135138

139+
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
136140
class CodegenTestCase(CompilationStepTestCase):
137141

138142
def generate_code(self, ast):
139-
insts, _ = compiler_codegen(ast, "my_file.py", 0)
143+
insts, _ = _testinternalcapi.compiler_codegen(ast, "my_file.py", 0)
140144
return insts
141145

142146

147+
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
143148
class CfgOptimizationTestCase(CompilationStepTestCase):
144149

145150
def get_optimized(self, insts, consts, nlocals=0):
146151
insts = self.normalize_insts(insts)
147152
insts = self.complete_insts_info(insts)
148-
insts = optimize_cfg(insts, consts, nlocals)
153+
insts = _testinternalcapi.optimize_cfg(insts, consts, nlocals)
149154
return insts, consts
150155

156+
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
151157
class AssemblerTestCase(CompilationStepTestCase):
152158

153159
def get_code_object(self, filename, insts, metadata):
154-
co = assemble_code_object(filename, insts, metadata)
160+
co = _testinternalcapi.assemble_code_object(filename, insts, metadata)
155161
return co

0 commit comments

Comments
 (0)