Skip to content

Commit 9b8314c

Browse files
authored
bpo-36611: Fix test_sys.test_getallocatedblocks() (GH-12797)
Fix test_sys.test_getallocatedblocks() when tracemalloc is enabled. If the name of Python memory allocators cannot get read, consider that pymalloc is disabled. Fix the following error: ./python -X tracemalloc -m test test_sys -v -m test_getallocatedblocks ERROR: test_getallocatedblocks (test.test_sys.SysModuleTest) ------------------------------------------------------------ Traceback (most recent call last): File "Lib/test/test_sys.py", line 770, in test_getallocatedblocks alloc_name = _testcapi.pymem_getallocatorsname() RuntimeError: cannot get allocators name
1 parent 9e4f2f3 commit 9b8314c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Lib/test/test_sys.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,13 @@ def test_getallocatedblocks(self):
767767
except ImportError:
768768
with_pymalloc = support.with_pymalloc()
769769
else:
770-
alloc_name = _testcapi.pymem_getallocatorsname()
771-
with_pymalloc = (alloc_name in ('pymalloc', 'pymalloc_debug'))
770+
try:
771+
alloc_name = _testcapi.pymem_getallocatorsname()
772+
except RuntimeError as exc:
773+
# "cannot get allocators name" (ex: tracemalloc is used)
774+
with_pymalloc = True
775+
else:
776+
with_pymalloc = (alloc_name in ('pymalloc', 'pymalloc_debug'))
772777

773778
# Some sanity checks
774779
a = sys.getallocatedblocks()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``test_sys.test_getallocatedblocks()`` when :mod:`tracemalloc` is
2+
enabled.

0 commit comments

Comments
 (0)