()
| 9 | |
| 10 | @pytest.mark.skipif(IS_WASM, reason="can't start subprocess") |
| 11 | def 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)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…