MCPcopy Index your code
hub / github.com/python/cpython / test_import_module

Function test_import_module

Lib/test/audit-tests.py:677–700  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

675 assertEqual(remote_event_script_path, tmp_file.name)
676
677def test_import_module():
678 import importlib
679
680 with TestHook() as hook:
681 importlib.import_module("importlib") # already imported, won't get logged
682 importlib.import_module("email") # standard library module
683 importlib.import_module("pythoninfo") # random module
684 importlib.import_module(".audit_test_data.submodule", "test") # relative import
685 importlib.import_module("test.audit_test_data.submodule2") # absolute import
686 importlib.import_module("_testcapi") # extension module
687
688 actual = [a for e, a in hook.seen if e == "import"]
689 assertSequenceEqual(
690 [
691 ("email", None, sys.path, sys.meta_path, sys.path_hooks),
692 ("pythoninfo", None, sys.path, sys.meta_path, sys.path_hooks),
693 ("test.audit_test_data.submodule", None, sys.path, sys.meta_path, sys.path_hooks),
694 ("test.audit_test_data", None, sys.path, sys.meta_path, sys.path_hooks),
695 ("test.audit_test_data.submodule2", None, sys.path, sys.meta_path, sys.path_hooks),
696 ("_testcapi", None, sys.path, sys.meta_path, sys.path_hooks),
697 ("_testcapi", unittest.mock.ANY, None, None, None)
698 ],
699 actual,
700 )
701
702def test_builtin__import__():
703 import importlib # noqa: F401

Callers

nothing calls this directly

Calls 3

assertSequenceEqualFunction · 0.85
TestHookClass · 0.70
import_moduleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…