MCPcopy Create free account
hub / github.com/numpy/numpy / test_lazy_load

Function test_lazy_load

numpy/tests/test_lazyloading.py:9–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7# Warning raised by _reload_guard() in numpy/__init__.py
8@pytest.mark.filterwarnings("ignore:The NumPy module was reloaded")
9def test_lazy_load():
10 # gh-22045. lazyload doesn't import submodule names into the namespace
11 # muck with sys.modules to test the importing system
12 old_numpy = sys.modules.pop("numpy")
13
14 numpy_modules = {}
15 for mod_name, mod in list(sys.modules.items()):
16 if mod_name[:6] == "numpy.":
17 numpy_modules[mod_name] = mod
18 sys.modules.pop(mod_name)
19
20 try:
21 # create lazy load of numpy as np
22 spec = find_spec("numpy")
23 module = module_from_spec(spec)
24 sys.modules["numpy"] = module
25 loader = LazyLoader(spec.loader)
26 loader.exec_module(module)
27 np = module
28
29 # test a subpackage import
30 from numpy.lib import recfunctions
31
32 # test triggering the import of the package
33 np.ndarray
34
35 finally:
36 if old_numpy:
37 sys.modules["numpy"] = old_numpy
38 sys.modules.update(numpy_modules)

Callers

nothing calls this directly

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected