diff --git a/CHANGELOG b/CHANGELOG index da1a01f..1bcb3db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,8 @@ - ``pytest-xdist`` now requires pytest 2.7 or later. +- Add ``worker_id`` attribute in the TestReport + 1.15.0 ------ diff --git a/README.rst b/README.rst index 468de90..2cafe8b 100644 --- a/README.rst +++ b/README.rst @@ -209,6 +209,10 @@ defined: * ``PYTEST_XDIST_WORKER_COUNT``: the total number of workers in this session, e.g., ``"4"`` when ``-n 4`` is given in the command-line. +The information about the worker_id in a test is stored in the TestReport as +well, under worker_id attribute. + + *New in version 1.15.* Specifying test exec environments in an ini file diff --git a/testing/test_newhooks.py b/testing/test_newhooks.py index a6737ea..ee79ebf 100644 --- a/testing/test_newhooks.py +++ b/testing/test_newhooks.py @@ -14,14 +14,19 @@ class TestHooks: def test_runtest_logreport(self, testdir): """Test that log reports from pytest_runtest_logreport when running - with xdist contain a "node" attribute. (#8) + with xdist contain "node", "nodeid" and "worker_id" attributes. (#8) """ testdir.makeconftest(""" def pytest_runtest_logreport(report): if hasattr(report, 'node'): - slaveid = report.node.slaveinput['slaveid'] if report.when == "call": - print("HOOK: %s %s" % (report.nodeid, slaveid)) + slaveid = report.node.slaveinput['slaveid'] + if slaveid != report.worker_id: + print("HOOK: Worker id mismatch: %s %s" + % (slaveid, report.worker_id)) + else: + print("HOOK: %s %s" + % (report.nodeid, report.worker_id)) """) res = testdir.runpytest('-n1', '-s') res.stdout.fnmatch_lines([ diff --git a/xdist/remote.py b/xdist/remote.py index 40bbeac..bdec4e8 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -88,6 +88,7 @@ class SlaveInteractor: def pytest_runtest_logreport(self, report): data = serialize_report(report) data["item_index"] = self.item_index + data["worker_id"] = self.slaveid assert self.session.items[self.item_index].nodeid == report.nodeid self.sendevent("testreport", data=data)