Skip to content

Commit 7182e65

Browse files
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 (cherry picked from commit 9b8314c) Co-authored-by: Victor Stinner <vstinner@redhat.com>
1 parent a910c2c commit 7182e65

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
@@ -768,8 +768,13 @@ def test_getallocatedblocks(self):
768768
except ImportError:
769769
with_pymalloc = support.with_pymalloc()
770770
else:
771-
alloc_name = _testcapi.pymem_getallocatorsname()
772-
with_pymalloc = (alloc_name in ('pymalloc', 'pymalloc_debug'))
771+
try:
772+
alloc_name = _testcapi.pymem_getallocatorsname()
773+
except RuntimeError as exc:
774+
# "cannot get allocators name" (ex: tracemalloc is used)
775+
with_pymalloc = True
776+
else:
777+
with_pymalloc = (alloc_name in ('pymalloc', 'pymalloc_debug'))
773778

774779
# Some sanity checks
775780
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)