]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-127906: Skip limited C API test_cext tests if Py_TRACE_REFS (#127993)
authorVictor Stinner <vstinner@python.org>
Mon, 16 Dec 2024 17:15:17 +0000 (18:15 +0100)
committerGitHub <noreply@github.com>
Mon, 16 Dec 2024 17:15:17 +0000 (18:15 +0100)
gh-127906: Skip limited C API test_cext tests if Py_TRACE_REFS

Skip limited C API tests in test_cext and test_cppext if Python is
configured with --with-trace-refs (if the Py_TRACE_REFS macro is
defined).

Lib/test/test_cext/__init__.py
Lib/test/test_cppext/__init__.py

index 9c6d98072481dd207f40f50896ac90bc6b26ba66..d5ea1dc66035b1cdafd0bab391e41bd1012bcc4f 100644 (file)
@@ -8,12 +8,14 @@ import os.path
 import shlex
 import shutil
 import subprocess
+import sys
 import unittest
 from test import support
 
 
 SOURCE = os.path.join(os.path.dirname(__file__), 'extension.c')
 SETUP = os.path.join(os.path.dirname(__file__), 'setup.py')
+Py_TRACE_REFS = hasattr(sys, 'getobjects')
 
 
 # With MSVC on a debug build, the linker fails with: cannot open file
@@ -47,6 +49,9 @@ class TestExt(unittest.TestCase):
         self.check_build('_test_limited_c11_cext', limited=True, std='c11')
 
     def check_build(self, extension_name, std=None, limited=False):
+        if limited and Py_TRACE_REFS:
+            self.skipTest('Py_LIMITED_API is incompatible with Py_TRACE_REFS')
+
         venv_dir = 'env'
         with support.setup_venv_with_pip_setuptools_wheel(venv_dir) as python_exe:
             self._check_build(extension_name, python_exe,
index cbd062adb322041813a91f06bc32eff03f35e014..2198b7b2c0ba4277bff91f0d6bd9c28ddabb53b4 100644 (file)
@@ -4,12 +4,14 @@ import os.path
 import shlex
 import shutil
 import subprocess
+import sys
 import unittest
 from test import support
 
 
 SOURCE = os.path.join(os.path.dirname(__file__), 'extension.cpp')
 SETUP = os.path.join(os.path.dirname(__file__), 'setup.py')
+Py_TRACE_REFS = hasattr(sys, 'getobjects')
 
 
 # With MSVC on a debug build, the linker fails with: cannot open file
@@ -45,6 +47,9 @@ class TestCPPExt(unittest.TestCase):
         self.check_build('_testcppext_limited', limited=True)
 
     def check_build(self, extension_name, std=None, limited=False):
+        if limited and Py_TRACE_REFS:
+            self.skipTest('Py_LIMITED_API is incompatible with Py_TRACE_REFS')
+
         venv_dir = 'env'
         with support.setup_venv_with_pip_setuptools_wheel(venv_dir) as python_exe:
             self._check_build(extension_name, python_exe,