Test cases that insert os.curdir ('.') into sys.path fail on WASI platforms. I think it is related how wasmtime maps directories into the runtime environment and how it sets up the current working directory. The test passes if I replace '.' with an empty string '' or remove the cached FileFinder instance for '.' with sys.path_importer_cache.pop('.').
./test-wasi.sh test_support -m test_forget
0:00:00 Run tests sequentially
0:00:00 [1/1] test_support
test test_support failed -- Traceback (most recent call last):
File "/Lib/test/test_support.py", line 116, in test_forget
mod = __import__(TESTFN)
^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '@test_66600_tmpæ'
test_support failed (1 error)
== Tests result: FAILURE ==
The culprit seems to be an outdated FileFinder instance: {'.': FileFinder('/.')}. The CWD is '/python-wasm/cpython/builddir/wasi/build/test_python_66600æ' when the test case is executed.
GH-93461 is the simplest solution I could come up with. importlib.invalidate_caches now drops all FileFinder instances if the cache key is not an absolute path.
Activity
pythongh-93461: Invalidate sys.path_importer_cache entries with relat…
tiran commented on Jun 9, 2022
GH-93461 is the simplest solution I could come up with. importlib.invalidate_caches now drops all FileFinder instances if the cache key is not an absolute path.
brettcannon commented on Jun 9, 2022
Seems like a reasonable solution to the problem.
gh-93461: Invalidate sys.path_importer_cache entries with relative pa…
pythongh-93461: Invalidate sys.path_importer_cache entries with relat…
gh-93461: Invalidate sys.path_importer_cache entries with relative pa…
brettcannon commented on Jun 17, 2022
@tiran can this be closed?
tiran commented on Jun 17, 2022
Yes, it is fixed now.
Revert 30935 defer bpo45162 to 312 (#94285)