|
29 | 29 | import pickle |
30 | 30 |
|
31 | 31 | import pytest |
| 32 | +from pathlib import Path |
32 | 33 |
|
33 | 34 | try: |
34 | 35 | # try importing numpy and scipy. These are not hard dependencies and |
@@ -1479,6 +1480,29 @@ def __getattr__(self, name): |
1479 | 1480 | finally: |
1480 | 1481 | sys.modules.pop("NonModuleObject") |
1481 | 1482 |
|
| 1483 | + def test_importing_multiprocessing_does_not_impact_whichmodule(self): |
| 1484 | + # non-regression test for #528 |
| 1485 | + pytest.importorskip("numpy") |
| 1486 | + script = textwrap.dedent(""" |
| 1487 | + import multiprocessing |
| 1488 | + import cloudpickle |
| 1489 | + from numpy import exp |
| 1490 | +
|
| 1491 | + print(cloudpickle.cloudpickle._whichmodule(exp, exp.__name__)) |
| 1492 | + """) |
| 1493 | + script_path = Path(self.tmpdir) / "whichmodule_and_multiprocessing.py" |
| 1494 | + with open(script_path, mode="w") as f: |
| 1495 | + f.write(script) |
| 1496 | + |
| 1497 | + proc = subprocess.Popen( |
| 1498 | + [sys.executable, str(script_path)], |
| 1499 | + stdout=subprocess.PIPE, |
| 1500 | + stderr=subprocess.STDOUT, |
| 1501 | + ) |
| 1502 | + out, _ = proc.communicate() |
| 1503 | + self.assertEqual(proc.wait(), 0) |
| 1504 | + self.assertEqual(out, b"numpy.core._multiarray_umath\n") |
| 1505 | + |
1482 | 1506 | def test_unrelated_faulty_module(self): |
1483 | 1507 | # Check that pickling a dynamically defined function or class does not |
1484 | 1508 | # fail when introspecting the currently loaded modules in sys.modules |
|
0 commit comments