-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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: Skip test module dependent tests if test modules are unavailable #117341
Changes from 1 commit
2757df4
3b0ee8e
7efd0ce
b07ca78
8d98770
979726b
cf8f208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff 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: | ||
|
@@ -244,6 +244,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 | ||
|
||
|
@@ -441,6 +442,7 @@ def static_method(): | |
|
||
NULL_OR_EMPTY = object() | ||
|
||
|
||
class FastCallTests(unittest.TestCase): | ||
"""Test calling using various callables from C | ||
""" | ||
|
@@ -484,49 +486,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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either do these in the class body, or revert the additions in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... or just require test modules for this test case; IMO we should not add too much complexity in order to make the test suite pass when test modules are unavailable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it's not too bad to do it in the class body. See 7efd0ce. |
||
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() | ||
|
||
|
@@ -546,6 +553,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() | ||
|
||
|
@@ -610,6 +618,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): | ||
|
@@ -1022,6 +1031,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): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import os | ||
import unittest | ||
from test.support import load_package_tests | ||
from test.support import TEST_MODULES | ||
|
||
|
||
if TEST_MODULES != "yes": | ||
raise unittest.SkipTest("requires test modules") | ||
|
||
|
||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps name this
TEST_MODULES_ENABLED
and make it a boolean.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea.
Also, IMO if
TEST_MODULES
has an unknown value the tests should not be skipped -- they should fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you might as well make the whole test suite fail in that case; if
TEST_MODULES
has an unknown value, something is more than a little bit off.