Skip to content

Commit 1818fba

Browse files
authored
Use _testlimitedcapi in test_free_threading.test_capi (#158935)
Replace ctypes with _testlimitedcapi. ctypes is not always available, and _testlimitedcapi is a thin wrapper to the C API. Skip the test if _testlimitedcapi is missing.
1 parent 6318730 commit 1818fba

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

‎Lib/test/test_free_threading/test_capi.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import ctypes.util
21
import sys
32
import unittest
43

4+
from test.support import import_helper
55
from test.support import threading_helper
66
from test.support.threading_helper import run_concurrently
77

8-
9-
@ctypes.util.wrap_dll_function(ctypes.pythonapi)
10-
def PyImport_AddModuleRef(name: ctypes.c_char_p) -> ctypes.py_object:
11-
pass
8+
# Skip the test if the extension is missing
9+
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
1210

1311

1412
@threading_helper.requires_working_threading()
@@ -20,6 +18,7 @@ def test_pyimport_addmoduleref_thread_safe(self):
2018
NUM_ITERS = 10
2119
NTHREADS = 4
2220

21+
PyImport_AddModuleRef = _testlimitedcapi.PyImport_AddModuleRef
2322
module_name = f"test_free_threading_addmoduleref_{id(self)}"
2423
module_name_bytes = module_name.encode()
2524
sys.modules.pop(module_name, None)

0 commit comments

Comments
 (0)