diff options
author | Victor Stinner <vstinner@python.org> | 2022-01-17 13:49:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-17 13:49:20 (GMT) |
commit | 16901c0482734dbd389b09ca3edfcf3e22faeed7 (patch) | |
tree | a22f75e121921624e2e985863ece71cc551d6299 | |
parent | ad6e640f910787e73fd00f59117fbd22cdf88c78 (diff) | |
download | cpython-16901c0482734dbd389b09ca3edfcf3e22faeed7.zip cpython-16901c0482734dbd389b09ca3edfcf3e22faeed7.tar.gz cpython-16901c0482734dbd389b09ca3edfcf3e22faeed7.tar.bz2 |
bpo-44133: Skip PyThread_get_thread_native_id() if not available (GH-30636)
test_capi.test_export_symbols() doesn't check if Python exports the
"PyThread_get_thread_native_id" symbol if the _thread.get_native_id()
function is not available (if the PY_HAVE_THREAD_NATIVE_ID macro is
not defined).
-rw-r--r-- | Lib/test/test_capi.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 9f21785..7ada840 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -2,6 +2,7 @@ # these are all functions _testcapi exports whose name begins with 'test_'. from collections import OrderedDict +import _thread import importlib.machinery import importlib.util import os @@ -648,7 +649,11 @@ class CAPITest(unittest.TestCase): # "PyThread_get_thread_native_id" symbols are exported by the Python # (directly by the binary, or via by the Python dynamic library). ctypes = import_helper.import_module('ctypes') - names = ['PyThread_get_thread_native_id'] + names = [] + + # Test if the PY_HAVE_THREAD_NATIVE_ID macro is defined + if hasattr(_thread, 'get_native_id'): + names.append('PyThread_get_thread_native_id') # Python/frozenmain.c fails to build on Windows when the symbols are # missing: @@ -657,6 +662,7 @@ class CAPITest(unittest.TestCase): # - PyInitFrozenExtensions if os.name != 'nt': names.append('Py_FrozenMain') + for name in names: with self.subTest(name=name): self.assertTrue(hasattr(ctypes.pythonapi, name)) |