diff options
author | Łukasz Langa <lukasz@langa.pl> | 2021-08-06 13:35:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-06 13:35:11 (GMT) |
commit | 693a661478036dc2c5b48e138dd09320a972c25a (patch) | |
tree | c7b2be448e0af106bbc22f38bcd91bbc244cdc2f | |
parent | 7dad0337518a0d599caf8f803a5bf45db67cbe9b (diff) | |
download | cpython-693a661478036dc2c5b48e138dd09320a972c25a.zip cpython-693a661478036dc2c5b48e138dd09320a972c25a.tar.gz cpython-693a661478036dc2c5b48e138dd09320a972c25a.tar.bz2 |
[3.9] bpo-40928: notify users running test_decimal on macOS of malloc warnings (GH-26783) (GH-27629)
* 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@langa.pl>.
(cherry picked from commit 15d3c14df32a35ac69898a7852115722e30d7857)
Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
-rw-r--r-- | Lib/test/support/__init__.py | 19 | ||||
-rw-r--r-- | Lib/test/test_decimal.py | 7 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index bc263b3..ff7db991 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -986,6 +986,25 @@ TEST_HOME_DIR = os.path.dirname(TEST_SUPPORT_DIR) # TEST_DATA_DIR is used as a target download location for remote resources 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 fd62f37..d37c53d 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -35,12 +35,17 @@ import locale from test.support import (run_unittest, run_doctest, is_resource_enabled, requires_IEEE_754, requires_docstrings) from test.support import (import_fresh_module, TestFailed, - run_with_locale, cpython_only) + run_with_locale, cpython_only, + darwin_malloc_err_warning) import random import inspect 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 0000000..c9a5e1b --- /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. |