At the time of writing this, it is *not* truly supported, but apparently enough users rely on it, for it to be an annoying change when it started failing previously.
()
| 46 | |
| 47 | @pytest.mark.skipif(IS_WASM, reason="can't start subprocess") |
| 48 | def test_full_reimport(): |
| 49 | """At the time of writing this, it is *not* truly supported, but |
| 50 | apparently enough users rely on it, for it to be an annoying change |
| 51 | when it started failing previously. |
| 52 | """ |
| 53 | # Test within a new process, to ensure that we do not mess with the |
| 54 | # global state during the test run (could lead to cryptic test failures). |
| 55 | # This is generally unsafe, especially, since we also reload the C-modules. |
| 56 | code = textwrap.dedent(r""" |
| 57 | import sys |
| 58 | from pytest import warns |
| 59 | import numpy as np |
| 60 | |
| 61 | for k in list(sys.modules.keys()): |
| 62 | if "numpy" in k: |
| 63 | del sys.modules[k] |
| 64 | |
| 65 | with warns(UserWarning): |
| 66 | import numpy as np |
| 67 | """) |
| 68 | p = subprocess.run([sys.executable, '-c', code], capture_output=True) |
| 69 | if p.returncode: |
| 70 | raise AssertionError( |
| 71 | f"Non-zero return code: {p.returncode!r}\n\n{p.stderr.decode()}" |
| 72 | ) |