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

Function namespace_tree_context

Lib/test/test_importlib/test_namespace_pkgs.py:40–54  ·  view source on GitHub ↗

Save import state and sys.modules cache and restore it on exit. Typical usage: >>> with namespace_tree_context(path=['/tmp/xxyy/portion1', ... '/tmp/xxyy/portion2']): ... pass

(**kwargs)

Source from the content-addressed store, hash-verified

38
39@contextlib.contextmanager
40def namespace_tree_context(**kwargs):
41 """
42 Save import state and sys.modules cache and restore it on exit.
43 Typical usage:
44
45 >>> with namespace_tree_context(path=['/tmp/xxyy/portion1',
46 ... '/tmp/xxyy/portion2']):
47 ... pass
48 """
49 # use default meta_path and path_hooks unless specified otherwise
50 kwargs.setdefault('meta_path', sys.meta_path)
51 kwargs.setdefault('path_hooks', sys.path_hooks)
52 import_context = util.import_state(**kwargs)
53 with import_context, sys_modules_context():
54 yield
55
56class NamespacePackageTest(unittest.TestCase):
57 """

Callers 1

setUpMethod · 0.85

Calls 2

sys_modules_contextFunction · 0.85
setdefaultMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…