MCPcopy Index your code
hub / github.com/numpy/numpy / test_lazy_load

Function test_lazy_load

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

Source from the content-addressed store, hash-verified

9
10@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")
11def test_lazy_load():
12 # gh-22045. lazyload doesn't import submodule names into the namespace
13
14 # Test within a new process, to ensure that we do not mess with the
15 # global state during the test run (could lead to cryptic test failures).
16 # This is generally unsafe, especially, since we also reload the C-modules.
17 code = textwrap.dedent(r"""
18 import sys
19 from importlib.util import LazyLoader, find_spec, module_from_spec
20
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 # noqa: F401
31
32 # test triggering the import of the package
33 np.ndarray
34 """)
35 run_subprocess((sys.executable, '-c', code))

Callers

nothing calls this directly

Calls 1

run_subprocessFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…