Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikmakait committed Jan 15, 2024
1 parent 68a68b1 commit bde4e14
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,30 @@ def __getattr__(self, name):
finally:
sys.modules.pop("NonModuleObject")

def test_importing_multiprocessing_does_not_impact_whichmodule(self):
# non-regression test for #528
np = pytest.importorskip("numpy")
script = """
import multiprocessing
import cloudpickle
from numpy import exp
print(cloudpickle.cloudpickle._whichmodule(exp, exp.__name__))
"""
script_path = os.path.join(self.tmpdir, "script.py")
with open(script_path, mode="w") as f:
f.write(script)

proc = subprocess.Popen(
[sys.executable, str(script_path)],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
out, _ = proc.communicate()
self.assertEqual(proc.wait(), 0)
self.assertEqual(out, b"numpy.core._multiarray_umath\n")


def test_unrelated_faulty_module(self):
# Check that pickling a dynamically defined function or class does not
# fail when introspecting the currently loaded modules in sys.modules
Expand Down

0 comments on commit bde4e14

Please sign in to comment.