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

Function import_module

Lib/test/support/import_helper.py:81–96  ·  view source on GitHub ↗

Import and return the module to be tested, raising SkipTest if it is not available. If deprecated is True, any module or package deprecation messages will be suppressed. If a module is required on a platform but optional for others, set required_on to an iterable of platform prefixe

(name, deprecated=False, *, required_on=())

Source from the content-addressed store, hash-verified

79
80
81def import_module(name, deprecated=False, *, required_on=()):
82 """Import and return the module to be tested, raising SkipTest if
83 it is not available.
84
85 If deprecated is True, any module or package deprecation messages
86 will be suppressed. If a module is required on a platform but optional for
87 others, set required_on to an iterable of platform prefixes which will be
88 compared against sys.platform.
89 """
90 with _ignore_deprecated_imports(deprecated):
91 try:
92 return importlib.import_module(name)
93 except ImportError as msg:
94 if sys.platform.startswith(tuple(required_on)):
95 raise
96 raise unittest.SkipTest(str(msg))
97
98
99def _save_and_remove_modules(names):

Callers 15

test_tty.pyFile · 0.90
test_refcount_errorsMethod · 0.90
test_readline.pyFile · 0.90
test_opcache.pyFile · 0.90
test_asyncgen.pyFile · 0.90
test_c_classMethod · 0.90
test_curses.pyFile · 0.90
detach_readlineMethod · 0.90
test_mmap.pyFile · 0.90

Calls 4

strFunction · 0.85
import_moduleMethod · 0.45
startswithMethod · 0.45

Tested by 15

test_refcount_errorsMethod · 0.72
test_c_classMethod · 0.72
detach_readlineMethod · 0.72
setUpClassMethod · 0.72
test_flock_overflowMethod · 0.72
test_subinterpMethod · 0.72
test_no_memoryMethod · 0.72
test_windows_messageMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…