|
def check_pythonmalloc(self, env_var, name): |
|
code = 'import _testinternalcapi; print(_testinternalcapi.pymem_getallocatorsname())' |
|
env = dict(os.environ) |
|
env.pop('PYTHONDEVMODE', None) |
|
if env_var is not None: |
|
env['PYTHONMALLOC'] = env_var |
|
else: |
|
env.pop('PYTHONMALLOC', None) |
|
args = (sys.executable, '-c', code) |
|
proc = subprocess.run(args, |
|
stdout=subprocess.PIPE, |
|
stderr=subprocess.STDOUT, |
|
universal_newlines=True, |
|
env=env) |
|
self.assertEqual(proc.stdout.rstrip(), name) |
|
self.assertEqual(proc.returncode, 0) |
|
|
|
def test_pythonmalloc(self): |
|
# Test the PYTHONMALLOC environment variable |
|
pymalloc = support.with_pymalloc() |
|
if pymalloc: |
|
default_name = 'pymalloc_debug' if support.Py_DEBUG else 'pymalloc' |
|
default_name_debug = 'pymalloc_debug' |
|
else: |
|
default_name = 'malloc_debug' if support.Py_DEBUG else 'malloc' |
|
default_name_debug = 'malloc_debug' |
|
|
|
tests = [ |
|
(None, default_name), |
|
('debug', default_name_debug), |
|
('malloc', 'malloc'), |
|
('malloc_debug', 'malloc_debug'), |
|
] |
|
if pymalloc: |
|
tests.extend(( |
|
('pymalloc', 'pymalloc'), |
|
('pymalloc_debug', 'pymalloc_debug'), |
|
)) |
|
|
|
for env_var, name in tests: |
|
with self.subTest(env_var=env_var, name=name): |
|
self.check_pythonmalloc(env_var, name) |
Bug report
I found at least three cases where
_testinternalcapiis just imported, we cannot do that, because other python implementation which reuse our test cases will fail on this.cpython/Lib/test/test_cmd_line.py
Lines 785 to 826 in 34ddcc3
cpython/Lib/test/test_import/__init__.py
Line 25 in 34ddcc3
cpython/Lib/test/test_opcache.py
Line 8 in 34ddcc3
There can be several options to solve this:
import _testinternalcapiwithexcept ImportError, when some places might need itimport_helper.import_moduleto skip some tests where this module is required@cpython_onlydecoratorLinked PRs
_testinternalcapiimports in tests #109722