Skip to content

GH-104289: Test importing all stdlib modules in subinterpreters #133392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,44 @@ def test_disallowed_reimport(self):
excsnap = _interpreters.run_string(interpid, script)
self.assertIsNot(excsnap, None)

def test_stdlib_compatible(self):
incompatible = frozenset({
'_curses', '_curses_panel',
'faulthandler',
'readline',
'_suggestions',
'_tkinter',
'_tracemalloc',
'_wmi',
'_zstd',
})

# collect all importable non-Python stdlib modules
supported_modules = set()
for module in sys.stdlib_module_names - incompatible:
# avoid importing pure-Python modules with side effects/warnings
spec = importlib.util.find_spec(module)
if isinstance(spec and spec.loader, ExtensionFileLoader):
try:
importlib.import_module(module)
except Exception:
pass
else:
supported_modules.add(module)

for module in supported_modules:
if not Py_GIL_DISABLED:
with self.subTest(f'{module}: not strict'):
self.check_compatible_here(module, strict=False)
with self.subTest(f'{module}: strict, not fresh'):
self.check_compatible_here(module, strict=True)
with self.subTest(f'{module}: strict, fresh'):
self.check_compatible_fresh(module, strict=True)
with self.subTest(f'{module}: isolated, not fresh'):
self.check_compatible_here(module, strict=True, isolated=True)
with self.subTest(f'{module}: isolated, fresh'):
self.check_compatible_fresh(module, strict=True, isolated=True)


class TestSinglePhaseSnapshot(ModuleSnapshot):
"""A representation of a single-phase init module for testing.
Expand Down
Loading