summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2022-08-17 11:48:43 (GMT)
committerGitHub <noreply@github.com>2022-08-17 11:48:43 (GMT)
commit0f2b469ce1a6f123ad9e151b1771651b3e1d2de6 (patch)
tree6b11c45f2eaa658bb8e6db56cd92b41435edcbae /Lib/test
parent7276ca25f5f1440aa4d025350d3de15141854dde (diff)
downloadcpython-0f2b469ce1a6f123ad9e151b1771651b3e1d2de6.zip
cpython-0f2b469ce1a6f123ad9e151b1771651b3e1d2de6.tar.gz
cpython-0f2b469ce1a6f123ad9e151b1771651b3e1d2de6.tar.bz2
gh-95991: Add some infrastructure for testing Limited API in _testcapi (GH-95992)
- Limited API needs to be enabled per source file - Some builds don't support Limited API, so Limited API tests must be skipped on those builds (currently this is `Py_TRACE_REFS`, but that may change.) - `Py_LIMITED_API` must be defined before `<Python.h>` is included. This puts the hoop-jumping in `testcapi/parts.h`, so individual test files can be relatively simple. (Currently that's only `vectorcall_limited.c`, imagine more.)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support/__init__.py10
-rw-r--r--Lib/test/test_call.py6
2 files changed, 12 insertions, 4 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index c51a1f2..2409fb0 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -46,6 +46,7 @@ __all__ = [
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_if_buggy_ucrt_strfptime",
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
+ "requires_limited_api",
# sys
"is_jython", "is_android", "is_emscripten", "is_wasi",
"check_impl_detail", "unix_shell", "setswitchinterval",
@@ -1069,6 +1070,15 @@ def refcount_test(test):
return no_tracing(cpython_only(test))
+def requires_limited_api(test):
+ try:
+ import _testcapi
+ except ImportError:
+ return unittest.skip('needs _testcapi module')(test)
+ return unittest.skipUnless(
+ _testcapi.LIMITED_API_AVAILABLE, 'needs Limited API support')(test)
+
+
def _filter_suite(suite, pred):
"""Recursively filter test cases in a suite based on a predicate."""
newtests = []
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index 131b45e..c00de27 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -1,5 +1,5 @@
import unittest
-from test.support import cpython_only
+from test.support import cpython_only, requires_limited_api
try:
import _testcapi
except ImportError:
@@ -760,9 +760,7 @@ class TestPEP590(unittest.TestCase):
self.assertEqual(expected, meth(*args1, **kwargs))
self.assertEqual(expected, wrapped(*args, **kwargs))
- @unittest.skipIf(
- hasattr(sys, 'getobjects'),
- "Limited API is not compatible with Py_TRACE_REFS")
+ @requires_limited_api
def test_vectorcall_limited(self):
from _testcapi import pyobject_vectorcall
obj = _testcapi.LimitedVectorCallClass()