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)
| 38 | |
| 39 | @contextlib.contextmanager |
| 40 | def 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 | |
| 56 | class NamespacePackageTest(unittest.TestCase): |
| 57 | """ |
no test coverage detected
searching dependent graphs…