Merge pull request #120 from KKoukiou/worker_id
Add worker_id into TestReport
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
- ``pytest-xdist`` now requires pytest 2.7 or later.
|
- ``pytest-xdist`` now requires pytest 2.7 or later.
|
||||||
|
|
||||||
|
- Add ``worker_id`` attribute in the TestReport
|
||||||
|
|
||||||
1.15.0
|
1.15.0
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ defined:
|
|||||||
* ``PYTEST_XDIST_WORKER_COUNT``: the total number of workers in this session,
|
* ``PYTEST_XDIST_WORKER_COUNT``: the total number of workers in this session,
|
||||||
e.g., ``"4"`` when ``-n 4`` is given in the command-line.
|
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.*
|
*New in version 1.15.*
|
||||||
|
|
||||||
Specifying test exec environments in an ini file
|
Specifying test exec environments in an ini file
|
||||||
|
|||||||
@@ -14,14 +14,19 @@ class TestHooks:
|
|||||||
|
|
||||||
def test_runtest_logreport(self, testdir):
|
def test_runtest_logreport(self, testdir):
|
||||||
"""Test that log reports from pytest_runtest_logreport when running
|
"""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("""
|
testdir.makeconftest("""
|
||||||
def pytest_runtest_logreport(report):
|
def pytest_runtest_logreport(report):
|
||||||
if hasattr(report, 'node'):
|
if hasattr(report, 'node'):
|
||||||
slaveid = report.node.slaveinput['slaveid']
|
|
||||||
if report.when == "call":
|
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 = testdir.runpytest('-n1', '-s')
|
||||||
res.stdout.fnmatch_lines([
|
res.stdout.fnmatch_lines([
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class SlaveInteractor:
|
|||||||
def pytest_runtest_logreport(self, report):
|
def pytest_runtest_logreport(self, report):
|
||||||
data = serialize_report(report)
|
data = serialize_report(report)
|
||||||
data["item_index"] = self.item_index
|
data["item_index"] = self.item_index
|
||||||
|
data["worker_id"] = self.slaveid
|
||||||
assert self.session.items[self.item_index].nodeid == report.nodeid
|
assert self.session.items[self.item_index].nodeid == report.nodeid
|
||||||
self.sendevent("testreport", data=data)
|
self.sendevent("testreport", data=data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user