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

Function test_full_reimport

numpy/tests/test_reloading.py:45–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43
44@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")
45def test_full_reimport():
46 # Reimporting numpy like this is not safe due to use of global C state,
47 # and has unexpected side effects. Test that an ImportError is raised.
48 # When all extension modules are isolated, this should test that clearing
49 # sys.modules and reimporting numpy works without error.
50
51 # Test within a new process, to ensure that we do not mess with the
52 # global state during the test run (could lead to cryptic test failures).
53 # This is generally unsafe, especially, since we also reload the C-modules.
54 code = textwrap.dedent(r"""
55 import sys
56 import numpy as np
57
58 for k in [k for k in sys.modules if k.startswith('numpy')]:
59 del sys.modules[k]
60
61 try:
62 import numpy as np
63 except ImportError as err:
64 if str(err) != "cannot load module more than once per process":
65 raise SystemExit(f"Unexpected ImportError: {err}")
66 else:
67 raise SystemExit("DID NOT RAISE ImportError")
68 """)
69 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…