Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-116303: Skip test module dependent tests if test modules are disabled#116307

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
40 commits
Select commitHold shift + click to select a range
9b3f0f7
gh-116303: Skip some sqlite3 tests if testcapi is unavailable
erlend-aaslandMar 4, 2024
0f6f74e
Skip more tests
erlend-aaslandMar 4, 2024
2f750c3
Split up sqlite3 tests
erlend-aaslandMar 4, 2024
7c4477d
Amend previous commit
erlend-aaslandMar 4, 2024
a9c6f62
Pull in main
erlend-aaslandMar 4, 2024
cdc6df4
Use import_helper iso. requires_limited_api
erlend-aaslandMar 5, 2024
d05dcd7
More skips
erlend-aaslandMar 5, 2024
cb7cff4
Fix gc and weakref tests
erlend-aaslandMar 5, 2024
ad5e3b6
Remove local debug stuff
erlend-aaslandMar 5, 2024
cdb8bf4
Fix test_os
erlend-aaslandMar 5, 2024
e4a30b0
Fixup stable_abi.py
erlend-aaslandMar 5, 2024
fabb007
Fixup run_in_subinterp
erlend-aaslandMar 5, 2024
c51dafa
Fixup test_call
erlend-aaslandMar 5, 2024
c3f9c99
Fixup test_audit
erlend-aaslandMar 5, 2024
fde9548
Fix some _testsinglephase issues
erlend-aaslandMar 5, 2024
ea72ced
Address review: use setUpClass in test_call; don't skip everything
erlend-aaslandMar 5, 2024
628896c
Address review: no need to skip in tearDown
erlend-aaslandMar 5, 2024
88c6739
Address review: check import at the top of test_threading.test_frame_…
erlend-aaslandMar 5, 2024
c02cd6f
Fixup some test.support helpers
erlend-aaslandMar 5, 2024
d49532b
Fixup test_coroutines
erlend-aaslandMar 5, 2024
2427111
Fixup test_threading
erlend-aaslandMar 5, 2024
25d0999
Fixup test_repl
erlend-aaslandMar 5, 2024
bdd8cff
Fixup test_monitoring
erlend-aaslandMar 5, 2024
ee9fa51
Amend test_embed
erlend-aaslandMar 5, 2024
a47c5ff
Amend test_audit
erlend-aaslandMar 5, 2024
d84a5c4
Fix test_socket
erlend-aaslandMar 5, 2024
e877ffb
Resolve test_exceptions nicer
erlend-aaslandMar 5, 2024
1ec0c66
Merge branch 'main' into sqlite/testcapi
erlend-aaslandMar 5, 2024
afa58a9
Use import_helper in test_importlib
erlend-aaslandMar 5, 2024
760c6cb
Fixup test_embed
erlend-aaslandMar 5, 2024
d7f060a
Pull in main
erlend-aaslandMar 5, 2024
a1106b7
Revert spurious docs change
erlend-aaslandMar 5, 2024
db45852
Workaround: use a different test module name in test_module_resources
erlend-aaslandMar 5, 2024
ccd8bea
gh-116307: Create a new import helper 'isolated modules' and use that…
jaracoMar 6, 2024
f80f75e
Merge branch 'main' into sqlite/testcapi
erlend-aaslandMar 6, 2024
39d135d
Revert "Workaround: use a different test module name in test_module_r…
erlend-aaslandMar 6, 2024
13c4829
Revert another spurious test_importlib change
erlend-aaslandMar 6, 2024
31e19a7
Fix test_embed
erlend-aaslandMar 7, 2024
45e0586
Pull in main
erlend-aaslandMar 7, 2024
a148fb5
Remove useless import from test_embed
erlend-aaslandMar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletionsLib/test/support/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -508,7 +508,7 @@ def has_no_debug_ranges():
try:
import _testinternalcapi
except ImportError:
raise unittest.SkipTest("_testinternalcapi required")
return unittest.skip("_testinternalcapi required")
config = _testinternalcapi.get_config()
return not bool(config['code_debug_ranges'])
Comment on lines +511 to 513

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why does it return a boolean (which is not callable) or a function (which always true)? How this helper is supposed to be used?


Expand DownExpand Up@@ -1704,7 +1704,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@@ -1714,7 +1717,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 DownExpand Up@@ -1876,12 +1882,18 @@ def restore(self):


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


Expand Down
11 changes: 7 additions & 4 deletionsLib/test/support/bytecode_helper.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@
import unittest
import dis
import io
from_testinternalcapi importcompiler_codegen, optimize_cfg, assemble_code_object
fromtest.support importimport_helper

_UNSPECIFIED = object()

Expand DownExpand 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
12 changes: 12 additions & 0 deletionsLib/test/support/import_helper.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,6 +268,18 @@ def modules_cleanup(oldmodules):
sys.modules.update(oldmodules)


@contextlib.contextmanager
def isolated_modules():
"""
Save modules on entry and cleanup on exit.
"""
(saved,) = modules_setup()
try:
yield
finally:
modules_cleanup(saved)


def mock_register_at_fork(func):
# bpo-30599: Mock os.register_at_fork() when importing the random module,
# since this function doesn't allow to unregister callbacks and would leak
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test__xxsubinterpreters.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,13 @@
import threading
import unittest

import _testinternalcapi
from test import support
from test.support import import_helper
from test.support import os_helper
from test.support import script_helper


_testinternalcapi = import_helper.import_module('_testinternalcapi')
interpreters = import_helper.import_module('_xxsubinterpreters')
from _xxsubinterpreters import InterpreterNotFoundError

Expand Down
1 change: 1 addition & 0 deletionsLib/test/test_audit.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,7 @@ def test_excepthook(self):
)

def test_unraisablehook(self):
import_helper.import_module("_testcapi")
returncode, events, stderr = self.run_python("test_unraisablehook")
if returncode:
self.fail(stderr)
Expand Down
84 changes: 47 additions & 37 deletionsLib/test/test_call.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import unittest
from test.support import (cpython_only, is_wasi, requires_limited_api, Py_DEBUG,
set_recursion_limit, skip_on_s390x)
set_recursion_limit, skip_on_s390x, import_helper)
try:
import _testcapi
except ImportError:
Expand DownExpand Up@@ -240,6 +240,7 @@ def test_module_not_callable_suggestion(self):
self.assertRaisesRegex(TypeError, msg, mod)


@unittest.skipIf(_testcapi is None, "requires _testcapi")
class TestCallingConventions(unittest.TestCase):
"""Test calling using various C calling conventions (METH_*) from Python

Expand DownExpand Up@@ -437,6 +438,7 @@ def static_method():

NULL_OR_EMPTY = object()


class FastCallTests(unittest.TestCase):
"""Test calling using various callables from C
"""
Expand DownExpand Up@@ -480,49 +482,54 @@ class FastCallTests(unittest.TestCase):
]

# Add all the calling conventions and variants of C callables
_instance = _testcapi.MethInstance()
for obj, expected_self in (
(_testcapi, _testcapi), # module-level function
(_instance, _instance), # bound method
(_testcapi.MethClass, _testcapi.MethClass), # class method on class
(_testcapi.MethClass(), _testcapi.MethClass), # class method on inst.
(_testcapi.MethStatic, None), # static method
):
CALLS_POSARGS.extend([
(obj.meth_varargs, (1, 2), (expected_self, (1, 2))),
(obj.meth_varargs_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall, (1, 2), (expected_self, (1, 2))),
(obj.meth_fastcall, (), (expected_self, ())),
(obj.meth_fastcall_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(), (expected_self, (), NULL_OR_EMPTY)),
(obj.meth_noargs, (), expected_self),
(obj.meth_o, (123, ), (expected_self, 123)),
])

CALLS_KWARGS.extend([
(obj.meth_varargs_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_varargs_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_varargs_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
])
@classmethod
def setUpClass(cls):
if _testcapi is None:
return
_instance = _testcapi.MethInstance()
for obj, expected_self in (
(_testcapi, _testcapi), # module-level function
(_instance, _instance), # bound method
(_testcapi.MethClass, _testcapi.MethClass), # class method on class
(_testcapi.MethClass(), _testcapi.MethClass), # class method on inst.
(_testcapi.MethStatic, None), # static method
):
cls.CALLS_POSARGS.extend([
(obj.meth_varargs, (1, 2), (expected_self, (1, 2))),
(obj.meth_varargs_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall, (1, 2), (expected_self, (1, 2))),
(obj.meth_fastcall, (), (expected_self, ())),
(obj.meth_fastcall_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(), (expected_self, (), NULL_OR_EMPTY)),
(obj.meth_noargs, (), expected_self),
(obj.meth_o, (123, ), (expected_self, 123)),
])

cls.CALLS_KWARGS.extend([
(obj.meth_varargs_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_varargs_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_varargs_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
])

def check_result(self, result, expected):
if isinstance(expected, tuple) and expected[-1] is NULL_OR_EMPTY:
if result[-1] in ({}, None):
expected = (*expected[:-1], result[-1])
self.assertEqual(result, expected)

@unittest.skipIf(_testcapi is None, "requires _testcapi")
def test_vectorcall_dict(self):
# Test PyObject_VectorcallDict()

Expand All@@ -542,6 +549,7 @@ def test_vectorcall_dict(self):
result = _testcapi.pyobject_fastcalldict(func, args, kwargs)
self.check_result(result, expected)

@unittest.skipIf(_testcapi is None, "requires _testcapi")
def test_vectorcall(self):
# Test PyObject_Vectorcall()

Expand DownExpand Up@@ -606,6 +614,7 @@ def testfunction_kw(self, *, kw):
ADAPTIVE_WARMUP_DELAY = 2


@unittest.skipIf(_testcapi is None, "requires _testcapi")
class TestPEP590(unittest.TestCase):

def test_method_descriptor_flag(self):
Expand DownExpand Up@@ -1018,6 +1027,7 @@ class TestRecursion(unittest.TestCase):

@skip_on_s390x
@unittest.skipIf(is_wasi and Py_DEBUG, "requires deep stack")
@unittest.skipIf(_testcapi is None, "requires _testcapi")
def test_super_deep(self):

def recurse(n):
Expand Down
2 changes: 1 addition & 1 deletionLib/test/test_capi/test_dict.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@
from collections import OrderedDict, UserDict
from types import MappingProxyType
from test import support
import_testcapi
_testcapi = support.import_helper.import_module("_testcapi")


NULL = None
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test_capi/test_opt.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,9 +6,9 @@
import gc
import os

import _testinternalcapi

from test.support import script_helper, requires_specialization
from test.support.import_helper import import_module
_testinternalcapi = import_module("_testinternalcapi")


@contextlib.contextmanager
Expand Down
7 changes: 3 additions & 4 deletionsLib/test/test_code.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,9 +143,8 @@
check_impl_detail, requires_debug_ranges,
gc_collect)
from test.support.script_helper import assert_python_ok
from test.support import threading_helper
from test.support.bytecode_helper import (BytecodeTestCase,
instructions_with_positions)
from test.support import threading_helper, import_helper
from test.support.bytecode_helper import instructions_with_positions
from opcode import opmap, opname
COPY_FREE_VARS = opmap['COPY_FREE_VARS']

Expand DownExpand Up@@ -176,7 +175,7 @@ class CodeTest(unittest.TestCase):

@cpython_only
def test_newempty(self):
import_testcapi
_testcapi = import_helper.import_module("_testcapi")
co = _testcapi.code_newempty("filename", "funcname", 15)
self.assertEqual(co.co_filename, "filename")
self.assertEqual(co.co_name, "funcname")
Expand Down
5 changes: 5 additions & 0 deletionsLib/test/test_coroutines.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,10 @@
from test.support import import_helper
from test.support import warnings_helper
from test.support.script_helper import assert_python_ok
try:
import _testcapi
except ImportError:
_testcapi = None


class AsyncYieldFrom:
Expand DownExpand Up@@ -2445,6 +2449,7 @@ def test_unawaited_warning_during_shutdown(self):


@support.cpython_only
@unittest.skipIf(_testcapi is None, "requires _testcapi")
class CAPITest(unittest.TestCase):

def test_tp_await_1(self):
Expand Down
3 changes: 2 additions & 1 deletionLib/test/test_ctypes/test_as_parameter.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
import _ctypes_test
import ctypes
import unittest
from ctypes import (Structure, CDLL, CFUNCTYPE,
POINTER, pointer, byref,
c_short, c_int, c_long, c_longlong,
c_byte, c_wchar, c_float, c_double,
ArgumentError)
from test.support import import_helper
_ctypes_test = import_helper.import_module("_ctypes_test")


dll = CDLL(_ctypes_test.__file__)
Expand Down
3 changes: 2 additions & 1 deletionLib/test/test_ctypes/test_bitfields.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
import _ctypes_test
import os
import unittest
from ctypes import (CDLL, Structure, sizeof, POINTER, byref, alignment,
Expand All@@ -7,6 +6,8 @@
c_uint32, c_uint64,
c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong)
from test import support
from test.support import import_helper
_ctypes_test = import_helper.import_module("_ctypes_test")


class BITS(Structure):
Expand Down
3 changes: 2 additions & 1 deletionLib/test/test_ctypes/test_callbacks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
import _ctypes_test
import ctypes
import functools
import gc
Expand All@@ -14,6 +13,8 @@
c_float, c_double, c_longdouble, py_object)
from ctypes.util import find_library
from test import support
from test.support import import_helper
_ctypes_test = import_helper.import_module("_ctypes_test")


class Callbacks(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletionLib/test/test_ctypes/test_cfuncs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
import _ctypes_test
import ctypes
import unittest
from ctypes import (CDLL,
c_byte, c_ubyte, c_char,
c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong,
c_float, c_double, c_longdouble)
from test.support import import_helper
_ctypes_test = import_helper.import_module("_ctypes_test")


class CFunctions(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletionLib/test/test_ctypes/test_checkretval.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
import _ctypes_test
import ctypes
import unittest
from ctypes import CDLL, c_int
from test.support import import_helper
_ctypes_test = import_helper.import_module("_ctypes_test")


class CHECKED(c_int):
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp