Skip to content

Commit 949af91

Browse files
committed
Set path for workers
1 parent f7c8c6c commit 949af91

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

python/tests/test_pickle_multiprocessing.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,25 @@
3333
import pickle
3434
import sys
3535
import threading
36+
from pathlib import Path
3637

3738
import pytest
3839
from datafusion import col, lit
3940

4041
from . import _pickle_multiprocessing_helpers as helpers
4142

43+
# `pytest --import-mode=importlib` (used in CI) does not prepend the test
44+
# parent directory to `sys.path`; pytest loads `tests` via its own importlib
45+
# hook. multiprocessing forkserver / spawn workers receive only the parent's
46+
# `sys.path` snapshot, not pytest's hook, so they fail to import
47+
# `tests._pickle_multiprocessing_helpers` with `ModuleNotFoundError: No module
48+
# named 'tests'`. Ensure the parent directory of the `tests` package is on
49+
# `sys.path` so workers can resolve it the standard way. Fork start method is
50+
# unaffected (inherits the already-imported module object).
51+
_TESTS_PARENT = str(Path(__file__).resolve().parent.parent)
52+
if _TESTS_PARENT not in sys.path:
53+
sys.path.insert(0, _TESTS_PARENT)
54+
4255

4356
@contextlib.contextmanager
4457
def _snapshot_on_hang(label: str, fire_after_seconds: float = 30.0):

0 commit comments

Comments
 (0)