Aluode/PerceptionLabPortable
0
1"""2Pyodide and other single-threaded Python builds will be missing the3_multiprocessing module. Test that joblib still works in this environment.4"""5 6import os7import subprocess8import sys9 10 11def test_missing_multiprocessing(tmp_path):12 """13 Test that import joblib works even if _multiprocessing is missing.14 15 pytest has already imported everything from joblib. The most reasonable way16 to test importing joblib with modified environment is to invoke a separate17 Python process. This also ensures that we don't break other tests by18 importing a bad `_multiprocessing` module.19 """20 (tmp_path / "_multiprocessing.py").write_text(21 'raise ImportError("No _multiprocessing module!")'22 )23 env = dict(os.environ)24 # For subprocess, use current sys.path with our custom version of25 # multiprocessing inserted.26 env["PYTHONPATH"] = ":".join([str(tmp_path)] + sys.path)27 subprocess.check_call(28 [29 sys.executable,30 "-c",31 "import joblib, math; "32 "joblib.Parallel(n_jobs=1)("33 "joblib.delayed(math.sqrt)(i**2) for i in range(10))",34 ],35 env=env,36 )37 