Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for missing _multiprocessing module #1246

Closed
wants to merge 10 commits into from
5 changes: 5 additions & 0 deletions joblib/test/missing_multiprocessing/_multiprocessing.py
@@ -0,0 +1,5 @@
"""
Simulate a missing _multiprocessing module by raising an ImportError.
test_missing_multiprocessing adds this folder to the path.
"""
raise ImportError("No _multiprocessing module!")
28 changes: 28 additions & 0 deletions joblib/test/test_missing_multiprocessing.py
@@ -0,0 +1,28 @@
"""
Pyodide and other single-threaded Python builds will be missing the
_multiprocessing module. Test that joblib still works in this environment.
"""

import os
import subprocess
import sys


def test_missing_multiprocessing():
"""
Test that import joblib works even if _multiprocessing is missing.

pytest has already imported everything from joblib. The most reasonable way
to test importing joblib with modified environment is to invoke a separate
Python process. This also ensures that we don't break other tests by
importing a bad `_multiprocessing` module.
"""
env = dict(os.environ)
# For subprocess, use current sys.path with our custom version of
# multiprocessing inserted.
import joblib

env["PYTHONPATH"] = ":".join(
[joblib.__path__[0] + "/test/missing_multiprocessing"] + sys.path
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
)
subprocess.check_call([sys.executable, "-c", "import joblib"], env=env)
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -16,6 +16,7 @@ addopts =
--doctest-modules
-p no:warnings
--ignore joblib/externals
--ignore joblib/test/missing_multiprocessing
testpaths = joblib

[flake8]
Expand Down