]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104533: Fix ctypes test_pointer_proto_missing_argtypes_error() (#154169)
authorVictor Stinner <vstinner@python.org>
Sun, 19 Jul 2026 16:24:12 +0000 (18:24 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2026 16:24:12 +0000 (16:24 +0000)
Save/restore Py_GetVersion.argtypes, since Py_GetVersion is used in
another test.

Lib/test/test_ctypes/test_pointers.py

index 771cc8fbe0ec934376bbf7bdfd39b9edf535f9ce..78480af34474a545b34f5643f44140a63cff42c8 100644 (file)
@@ -11,6 +11,7 @@ from ctypes import (CDLL, CFUNCTYPE, Structure,
                     c_long, c_ulong, c_longlong, c_ulonglong,
                     c_float, c_double)
 from ctypes import _pointer_type_cache, _pointer_type_cache_fallback
+from test import support
 from test.support import import_helper
 from weakref import WeakSet
 _ctypes_test = import_helper.import_module("_ctypes_test")
@@ -409,10 +410,9 @@ class PointersTestCase(unittest.TestCase):
             pass
 
         func = ctypes.pythonapi.Py_GetVersion
-        func.argtypes = (BadType,)
-
-        with self.assertRaises(ctypes.ArgumentError):
-            func(object())
+        with support.swap_attr(func, 'argtypes', (BadType,)):
+            with self.assertRaises(ctypes.ArgumentError):
+                func(object())
 
 class PointerTypeCacheTestCase(unittest.TestCase):
     # dummy tests to check warnings and base behavior