]> granicus.if.org Git - python/commitdiff
bpo-36611: Fix test_sys.test_getallocatedblocks() (GH-12797)
authorVictor Stinner <vstinner@redhat.com>
Fri, 12 Apr 2019 13:15:04 +0000 (15:15 +0200)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2019 13:15:04 +0000 (15:15 +0200)
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

Lib/test/test_sys.py
Misc/NEWS.d/next/Tests/2019-04-12-12-44-42.bpo-36611.UtorXL.rst [new file with mode: 0644]

index 4bd54af3629c8828176b3691e3313d57c730e732..d1c7daad7bba48301457bd139686c909ecdb966a 100644 (file)
@@ -767,8 +767,13 @@ class SysModuleTest(unittest.TestCase):
         except ImportError:
             with_pymalloc = support.with_pymalloc()
         else:
-            alloc_name = _testcapi.pymem_getallocatorsname()
-            with_pymalloc = (alloc_name in ('pymalloc', 'pymalloc_debug'))
+            try:
+                alloc_name = _testcapi.pymem_getallocatorsname()
+            except RuntimeError as exc:
+                # "cannot get allocators name" (ex: tracemalloc is used)
+                with_pymalloc = True
+            else:
+                with_pymalloc = (alloc_name in ('pymalloc', 'pymalloc_debug'))
 
         # Some sanity checks
         a = sys.getallocatedblocks()
diff --git a/Misc/NEWS.d/next/Tests/2019-04-12-12-44-42.bpo-36611.UtorXL.rst b/Misc/NEWS.d/next/Tests/2019-04-12-12-44-42.bpo-36611.UtorXL.rst
new file mode 100644 (file)
index 0000000..e4da7f1
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``test_sys.test_getallocatedblocks()`` when :mod:`tracemalloc` is
+enabled.