diff --git a/changelog/332.bugfix.rst b/changelog/332.bugfix.rst new file mode 100644 index 0000000..467c0e5 --- /dev/null +++ b/changelog/332.bugfix.rst @@ -0,0 +1 @@ +Fix report of module-level skips (``pytest.skip(reason, allow_module_level=True)``). diff --git a/testing/test_remote.py b/testing/test_remote.py index 611ecba..05e4380 100644 --- a/testing/test_remote.py +++ b/testing/test_remote.py @@ -1,6 +1,8 @@ import py import pprint import pytest +from pkg_resources import parse_version + from xdist.workermanage import WorkerController, unserialize_report from xdist.remote import serialize_report import execnet @@ -293,13 +295,14 @@ class TestWorkerInteractor: assert "workeroutput" in ev.kwargs @pytest.mark.skipif( - pytest.__version__ >= "3.0", reason="skip at module level illegal in pytest 3.0" + parse_version(pytest.__version__) < parse_version("3.3"), + reason="skip at module level illegal in this pytest version", ) def test_remote_collect_skip(self, worker): worker.testdir.makepyfile( """ - import py - py.test.skip("hello") + import pytest + pytest.skip("hello", allow_module_level=True) """ ) worker.setup() @@ -307,10 +310,9 @@ class TestWorkerInteractor: assert not ev.kwargs ev = worker.popevent() assert ev.name == "collectreport" - ev = worker.popevent() - assert ev.name == "collectreport" rep = unserialize_report(ev.name, ev.kwargs["data"]) assert rep.skipped + assert rep.longrepr[2] == "Skipped: hello" ev = worker.popevent("collectionfinish") assert not ev.kwargs["ids"] diff --git a/xdist/dsession.py b/xdist/dsession.py index bc960d3..be3ba77 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -259,10 +259,10 @@ class DSession(object): def worker_collectreport(self, node, rep): """Emitted when a node calls the pytest_collectreport hook. - Because we only need the report when there's a failure, as optimization - we only expect to receive failed reports from workers (#330). + Because we only need the report when there's a failure/skip, as optimization + we only expect to receive failed/skipped reports from workers (#330). """ - assert rep.failed + assert not rep.passed self._failed_worker_collectreport(node, rep) def worker_logwarning(self, message, code, nodeid, fslocation): diff --git a/xdist/remote.py b/xdist/remote.py index 66b270c..a0afa49 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -110,8 +110,8 @@ class WorkerInteractor(object): self.sendevent("testreport", data=data) def pytest_collectreport(self, report): - # master only needs reports that failed, as optimization send only them instead (#330) - if report.failed: + # send only reports that have not passed to master as optimization (#330) + if not report.passed: data = serialize_report(report) self.sendevent("collectreport", data=data)