From b776d4696dd2d1065eddcaa7cb0f3fa50215e942 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 12 Sep 2026 04:34:01 +0200 Subject: [PATCH] gh-157242: Fix test_capi on Py_TRACE_REFS build Mark tests using set_nomemory() with @support.nomemtest to skip these tests on a Py_TRACE_REFS build. --- Lib/test/test_bytes.py | 2 ++ Lib/test/test_capi/test_bytes.py | 6 ++++++ Modules/_testcapi/mem.c | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 0f21ffb5ecb9b4f..4b2bed9a0a56446 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -1569,6 +1569,7 @@ def test_resize(self): self.assertRaises(MemoryError, bytearray().resize, sys.maxsize) self.assertRaises(MemoryError, bytearray(1000).resize, sys.maxsize) + @support.nomemtest def test_resize_error(self): # gh-157242: If bytearray.resize() fails (MemoryError), # the bytearray must be left unchanged. @@ -1662,6 +1663,7 @@ def test_take_bytes(self): self.assertEqual(ba, bytearray(b'A')) self.assertEqual(ord(b'c'), ord('c')) + @support.nomemtest def test_take_bytes_error(self): # gh-157242: If bytearray.take_bytes() fails (MemoryError), # the bytearray must be left unchanged. diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py index 2c0476f2e1faf3d..0a925cf194b9825 100644 --- a/Lib/test/test_capi/test_bytes.py +++ b/Lib/test/test_capi/test_bytes.py @@ -1,5 +1,6 @@ import sys import unittest +from test import support from test.support import import_helper _testlimitedcapi = import_helper.import_module('_testlimitedcapi') @@ -389,6 +390,7 @@ def test_resize(self): writer.resize(len(b'number=123456'), b'456') self.assertEqual(writer.finish(), self.result_type(b'number=123456')) + @support.nomemtest def test_resize_error(self): small_buffer = _testcapi.PyBytesWriter_small_buffer init = b'x' * (small_buffer * 2) @@ -464,6 +466,10 @@ def test_example_resize(self): def test_example_highlevel(self): self.assertEqual(_testcapi.byteswriter_highlevel(), b'Hello World!') + @support.nomemtest + def test_bytes_resize_tracer(self): + _testcapi._test_bytes_resize_tracer() + class ByteArrayWriterTest(BaseWriterTest, unittest.TestCase): result_type = bytearray diff --git a/Modules/_testcapi/mem.c b/Modules/_testcapi/mem.c index 4ae6a60ff39d157..cdd9465d9b3dc96 100644 --- a/Modules/_testcapi/mem.c +++ b/Modules/_testcapi/mem.c @@ -943,7 +943,7 @@ check_bytes_resize_tracer(int no_memory) static PyObject* -test_bytes_resize_tracer(PyObject *self, PyObject *Py_UNUSED(ignored)) +_test_bytes_resize_tracer(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (check_bytes_resize_tracer(0) < 0) { return NULL; @@ -972,7 +972,7 @@ static PyMethodDef test_methods[] = { #if TARGET_OS_OSX || defined(__FreeBSD__) {"get_process_memory_usage", get_process_memory_usage, METH_VARARGS}, #endif - {"test_bytes_resize_tracer", test_bytes_resize_tracer, METH_NOARGS}, + {"_test_bytes_resize_tracer", _test_bytes_resize_tracer, METH_NOARGS}, // Tracemalloc tests {"tracemalloc_track", tracemalloc_track, METH_VARARGS},