Merge pull request #120 from KKoukiou/worker_id

Add worker_id into TestReport
This commit is contained in:
Ronny Pfannschmidt
2017-02-16 10:24:41 +01:00
committed by GitHub
4 changed files with 15 additions and 3 deletions

View File

@@ -3,6 +3,8 @@
- ``pytest-xdist`` now requires pytest 2.7 or later.
- Add ``worker_id`` attribute in the TestReport
1.15.0
------

View File

@@ -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

View File

@@ -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([

View File

@@ -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)