[Python-checkins] bpo-40928: notify users running test_decimal on macOS of malloc warnings (GH-26783)

miss-islington webhook-mailer at python.org
Fri Aug 6 13:09:11 EDT 2021


https://github.com/python/cpython/commit/a5d99632766b458b42f327e8bd0f82b0345c9a63
commit: a5d99632766b458b42f327e8bd0f82b0345c9a63
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-08-06T10:09:06-07:00
summary:

bpo-40928: notify users running test_decimal on macOS of malloc warnings (GH-26783)


* When trying to allocate very large regions on macOS, malloc does not   fail silently. It sends a noisy error out to STDERR
* This provides a helper function to warn the user, and provides the warning for test_decimal, which consistently generates these warnings on macOS.

Co-authored-by: Łukasz Langa <lukasz at langa.pl>
(cherry picked from commit 15d3c14df32a35ac69898a7852115722e30d7857)

Co-authored-by: Jack DeVries <58614260+jdevries3133 at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst
M Lib/test/support/__init__.py
M Lib/test/test_decimal.py

diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 4a2ed1ea5ae0c0..cb3acecbbd1197 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -459,6 +459,24 @@ def requires_lzma(reason='requires lzma'):
 TEST_DATA_DIR = os.path.join(TEST_HOME_DIR, "data")
 
 
+def darwin_malloc_err_warning(test_name):
+    """Assure user that loud errors generated by macOS libc's malloc are
+    expected."""
+    if sys.platform != 'darwin':
+        return
+
+    import shutil
+    msg = ' NOTICE '
+    detail = (f'{test_name} may generate "malloc can\'t allocate region"\n'
+              'warnings on macOS systems. This behavior is known. Do not\n'
+              'report a bug unless tests are also failing. See bpo-40928.')
+
+    padding, _ = shutil.get_terminal_size()
+    print(msg.center(padding, '-'))
+    print(detail)
+    print('-' * padding)
+
+
 def findfile(filename, subdir=None):
     """Try to find a file on sys.path or in the test directory.  If it is not
     found the argument passed to the function is returned (this does not
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 058829b03a3dee..28d56909b30034 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -36,7 +36,8 @@
                           requires_IEEE_754, requires_docstrings,
                           requires_legacy_unicode_capi)
 from test.support import (TestFailed,
-                          run_with_locale, cpython_only)
+                          run_with_locale, cpython_only,
+                          darwin_malloc_err_warning)
 from test.support.import_helper import import_fresh_module
 from test.support import warnings_helper
 import random
@@ -44,6 +45,10 @@
 import threading
 
 
+if sys.platform == 'darwin':
+    darwin_malloc_err_warning('test_decimal')
+
+
 C = import_fresh_module('decimal', fresh=['_decimal'])
 P = import_fresh_module('decimal', blocked=['_decimal'])
 orig_sys_decimal = sys.modules['decimal']
diff --git a/Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst b/Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst
new file mode 100644
index 00000000000000..c9a5e1b01e58aa
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst
@@ -0,0 +1,2 @@
+Notify users running test_decimal regression tests on macOS of potential
+harmless "malloc can't allocate region" messages spewed by test_decimal.



More information about the Python-checkins mailing list