diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-04-12 13:33:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-12 13:33:31 (GMT) |
commit | 7182e653fb5c6f78f05892b6ed302fc8db8978d3 (patch) | |
tree | 8e7fe83777fac38ab04e05401a88214e2698e7bb | |
parent | a910c2c6f3542b61f084de2ece0d8dab09c5a0fa (diff) | |
download | cpython-7182e653fb5c6f78f05892b6ed302fc8db8978d3.zip cpython-7182e653fb5c6f78f05892b6ed302fc8db8978d3.tar.gz cpython-7182e653fb5c6f78f05892b6ed302fc8db8978d3.tar.bz2 |
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 9b8314cfe29ca532fc335277f6c36b72e6132922)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
-rw-r--r-- | Lib/test/test_sys.py | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2019-04-12-12-44-42.bpo-36611.UtorXL.rst | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 27f7590..ef3fee1 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -768,8 +768,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 index 0000000..e4da7f1 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-04-12-12-44-42.bpo-36611.UtorXL.rst @@ -0,0 +1,2 @@ +Fix ``test_sys.test_getallocatedblocks()`` when :mod:`tracemalloc` is +enabled. |