Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

### 1.10.6 - bugfixes and maintenance chores
### 1.10.6 - bugfix and maintenance

- Fixed EOFError during pytest session finish in some conditions, with `pytest-xdist plugin` and `-n` option
activated. Fixed [#72](https://github.com/smarie/python-pytest-harvest/issues/72).
- Refactored layout and CI. Fixed [#56](https://github.com/smarie/python-pytest-harvest/issues/56).

### 1.10.5 - pytest 8.1 compat
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ install_requires =
six
pathlib2;python_version<'3.2'
tests_require =
; cloudpickle
pytest
numpy
pandas
Expand Down
17 changes: 14 additions & 3 deletions src/pytest_harvest/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pickle
from collections import OrderedDict
from logging import warning
from shutil import rmtree
Expand Down Expand Up @@ -399,6 +398,14 @@ def __init__(self, config):

@pytest.hookimpl(trylast=True)
def pytest_harvest_xdist_init(self):
try:
import cloudpickle
except ImportError as e:
print("ERROR : `cloudpickle` must be installed for `pytest-harvest` to collect distributed results from "
"`pytest-xdist` parallel workers. If you do not wish to install cloudpickle, please remove the '-n' "
"option from the commandline to disable xdist parallelization.\n")
raise e

# reset the recipient folder
if self.results_path.exists():
rmtree(str(self.results_path))
Expand All @@ -407,20 +414,24 @@ def pytest_harvest_xdist_init(self):

@pytest.hookimpl(trylast=True)
def pytest_harvest_xdist_worker_dump(self, worker_id, session_items, fixture_store):
import cloudpickle

with open(str(self.results_path / ('%s.pkl' % worker_id)), 'wb') as f:
try:
pickle.dump((session_items, fixture_store), f)
cloudpickle.dump((session_items, fixture_store), f)
except Exception as e:
warning("Error while pickling worker %s's harvested results: [%s] %s", (worker_id, e.__class__, e))
return True

@pytest.hookimpl(trylast=True)
def pytest_harvest_xdist_load(self):
import cloudpickle

workers_saved_material = dict()
for pkl_file in self.results_path.glob('*.pkl'):
wid = pkl_file.stem
with pkl_file.open('rb') as f:
workers_saved_material[wid] = pickle.load(f)
workers_saved_material[wid] = cloudpickle.load(f)
return workers_saved_material

@pytest.hookimpl(trylast=True)
Expand Down