-
Notifications
You must be signed in to change notification settings - Fork 9
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
EOFError during pytest session finish with pytest_xdist plugin #72
Comments
I found out that cloudpickle can solve this issue. I recommend the library will switch to it :) cc @smarie # conftest.py
import cloudpickle # type: ignore
from typing import OrderedDict, Dict, Any
from logging import warning
from pathlib import Path
from shutil import rmtree
# ## Xdist harvesting using cloudpickle instead of pytest-harvest's default pickling
# ## This is useful when the harvested objects are not serializable by pytest-harvest's default pickling.
RESULTS_PATH = Path('./.xdist_harvested/')
def pytest_harvest_xdist_init() -> bool:
if RESULTS_PATH.exists():
rmtree(RESULTS_PATH)
RESULTS_PATH.mkdir(exist_ok=False)
return True
def pytest_harvest_xdist_worker_dump(worker_id: str, session_items: Any, fixture_store: OrderedDict[Any, Any]) -> bool:
with open(RESULTS_PATH / f'{worker_id}.pkl', 'wb') as f:
try:
cloudpickle.dump((session_items, fixture_store), f)
except Exception as e:
warning(f"Error while pickling worker {worker_id}'s harvested results: [{e.__class__}] {e}")
return True
def pytest_harvest_xdist_load() -> Dict[str, Any]:
workers_saved_material = dict()
for pkl_file in RESULTS_PATH.glob('*.pkl'):
wid = pkl_file.stem
with pkl_file.open('rb') as f:
workers_saved_material[wid] = cloudpickle.load(f)
return workers_saved_material
def pytest_harvest_xdist_cleanup() -> bool:
rmtree(RESULTS_PATH)
return True |
smarie
pushed a commit
that referenced
this issue
Sep 30, 2024
…`pytest-xdist plugin` and `-n` option activated. Fixed #72
Hi both, thanks a lot @junuMoon for finding this issue and @AlmogBaku for finding a solution ! I cannot reproduce the issue on my side, so @junuMoon can you please
Thanks a lot ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cmd
Env
Error Traceback
The text was updated successfully, but these errors were encountered: