Skip to content
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

gh-116303: Handle disabled test modules in test.support #116482

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions Lib/test/support/__init__.py
Expand Up @@ -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)


Expand All @@ -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
Expand Down Expand Up @@ -1887,13 +1893,12 @@ def restore(self):


def with_pymalloc():
import _testcapi
return _testcapi.WITH_PYMALLOC and not Py_GIL_DISABLED
WITH_PYMALLOC = bool(sysconfig.get_config_var("WITH_PYMALLOC"))
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
return WITH_PYMALLOC and not Py_GIL_DISABLED


def with_mimalloc():
import _testcapi
return _testcapi.WITH_MIMALLOC
return bool(sysconfig.get_config_var("WITH_MIMALLOC"))


class _ALWAYS_EQ:
Expand Down
11 changes: 7 additions & 4 deletions Lib/test/support/bytecode_helper.py
Expand Up @@ -3,7 +3,7 @@
import unittest
import dis
import io
from _testinternalcapi import compiler_codegen, optimize_cfg, assemble_code_object
from test.support import import_helper

_UNSPECIFIED = object()

Expand Down Expand Up @@ -136,20 +136,23 @@ def complete_insts_info(self, insts):
class CodegenTestCase(CompilationStepTestCase):

def generate_code(self, ast):
insts, _ = compiler_codegen(ast, "my_file.py", 0)
_testinternalcapi = import_helper.import_module("_testinternalcapi")
insts, _ = _testinternalcapi.compiler_codegen(ast, "my_file.py", 0)
return insts


class CfgOptimizationTestCase(CompilationStepTestCase):

def get_optimized(self, insts, consts, nlocals=0):
_testinternalcapi = import_helper.import_module("_testinternalcapi")
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

class AssemblerTestCase(CompilationStepTestCase):

def get_code_object(self, filename, insts, metadata):
co = assemble_code_object(filename, insts, metadata)
_testinternalcapi = import_helper.import_module("_testinternalcapi")
co = _testinternalcapi.assemble_code_object(filename, insts, metadata)
return co