Skip to content

Commit 15d3c14

Browse files
jdevries3133ambv
andauthored
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 <[email protected]>
1 parent 4d77691 commit 15d3c14

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Lib/test/support/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,24 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
467467
TEST_DATA_DIR = os.path.join(TEST_HOME_DIR, "data")
468468

469469

470+
def darwin_malloc_err_warning(test_name):
471+
"""Assure user that loud errors generated by macOS libc's malloc are
472+
expected."""
473+
if sys.platform != 'darwin':
474+
return
475+
476+
import shutil
477+
msg = ' NOTICE '
478+
detail = (f'{test_name} may generate "malloc can\'t allocate region"\n'
479+
'warnings on macOS systems. This behavior is known. Do not\n'
480+
'report a bug unless tests are also failing. See bpo-40928.')
481+
482+
padding, _ = shutil.get_terminal_size()
483+
print(msg.center(padding, '-'))
484+
print(detail)
485+
print('-' * padding)
486+
487+
470488
def findfile(filename, subdir=None):
471489
"""Try to find a file on sys.path or in the test directory. If it is not
472490
found the argument passed to the function is returned (this does not

Lib/test/test_decimal.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@
3636
requires_IEEE_754, requires_docstrings,
3737
requires_legacy_unicode_capi)
3838
from test.support import (TestFailed,
39-
run_with_locale, cpython_only)
39+
run_with_locale, cpython_only,
40+
darwin_malloc_err_warning)
4041
from test.support.import_helper import import_fresh_module
4142
from test.support import warnings_helper
4243
import random
4344
import inspect
4445
import threading
4546

4647

48+
if sys.platform == 'darwin':
49+
darwin_malloc_err_warning('test_decimal')
50+
51+
4752
C = import_fresh_module('decimal', fresh=['_decimal'])
4853
P = import_fresh_module('decimal', blocked=['_decimal'])
4954
orig_sys_decimal = sys.modules['decimal']
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Notify users running test_decimal regression tests on macOS of potential
2+
harmless "malloc can't allocate region" messages spewed by test_decimal.

0 commit comments

Comments
 (0)