Skip to content

Commit 8f6f59f

Browse files
committed
Test importing all stdlib modules in subinterpreters
1 parent 0a1fedb commit 8f6f59f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Lib/test/test_import/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,44 @@ def test_disallowed_reimport(self):
25392539
excsnap = _interpreters.run_string(interpid, script)
25402540
self.assertIsNot(excsnap, None)
25412541

2542+
def test_stdlib_compatible(self):
2543+
incompatible = frozenset({
2544+
'_curses', '_curses_panel',
2545+
'faulthandler',
2546+
'readline',
2547+
'_suggestions',
2548+
'_tkinter',
2549+
'_tracemalloc',
2550+
'_wmi',
2551+
'_zstd',
2552+
})
2553+
2554+
# collect all importable non-Python stdlib modules
2555+
supported_modules = set()
2556+
for module in sys.stdlib_module_names - incompatible:
2557+
# avoid importing pure-Python modules with side effects/warnings
2558+
spec = importlib.util.find_spec(module)
2559+
if isinstance(spec and spec.loader, ExtensionFileLoader):
2560+
try:
2561+
importlib.import_module(module)
2562+
except Exception:
2563+
pass
2564+
else:
2565+
supported_modules.add(module)
2566+
2567+
for module in supported_modules:
2568+
if not Py_GIL_DISABLED:
2569+
with self.subTest(f'{module}: not strict'):
2570+
self.check_compatible_here(module, strict=False)
2571+
with self.subTest(f'{module}: strict, not fresh'):
2572+
self.check_compatible_here(module, strict=True)
2573+
with self.subTest(f'{module}: strict, fresh'):
2574+
self.check_compatible_fresh(module, strict=True)
2575+
with self.subTest(f'{module}: isolated, not fresh'):
2576+
self.check_compatible_here(module, strict=True, isolated=True)
2577+
with self.subTest(f'{module}: isolated, fresh'):
2578+
self.check_compatible_fresh(module, strict=True, isolated=True)
2579+
25422580

25432581
class TestSinglePhaseSnapshot(ModuleSnapshot):
25442582
"""A representation of a single-phase init module for testing.

0 commit comments

Comments
 (0)