Skip to content

Commit d047407

Browse files
committed
Transfer warnings from workers to master
Fix pytest-dev#92
1 parent 02754d8 commit d047407

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

changelog/92.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warnings are now properly transferred from workers to the master node.

testing/acceptance_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ def test_func():
339339
"E assert 0",
340340
])
341341

342+
@pytest.mark.parametrize('n', ['-n0', '-n1'])
343+
def test_logwarning(self, testdir, n):
344+
testdir.makepyfile("""
345+
import warnings
346+
def test_func():
347+
warnings.warn('this is a warning')
348+
""")
349+
result = testdir.runpytest(n)
350+
result.stdout.fnmatch_lines([
351+
"*this is a warning*",
352+
])
353+
342354

343355
def test_teardownfails_one_function(testdir):
344356
p = testdir.makepyfile("""

xdist/dsession.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ def slave_collectreport(self, node, rep):
247247
if rep.failed:
248248
self._failed_slave_collectreport(node, rep)
249249

250+
def slave_logwarning(self, message, code, nodeid, fslocation):
251+
"""Emitted when a node calls the pytest_logwarning hook."""
252+
kwargs = dict(message=message, code=code, nodeid=nodeid, fslocation=fslocation)
253+
self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs)
254+
250255
def _clone_node(self, node):
251256
"""Return new node based on an existing one.
252257

xdist/remote.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def pytest_collectreport(self, report):
9696
data = serialize_report(report)
9797
self.sendevent("collectreport", data=data)
9898

99+
def pytest_logwarning(self, message, code, nodeid, fslocation):
100+
self.sendevent("logwarning", message=message, code=code, nodeid=nodeid, fslocation=fslocation)
101+
99102

100103
def serialize_report(rep):
101104
def disassembled_report(rep):

xdist/slavemanage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ def process_from_remote(self, eventcall): # noqa too complex
315315
self.notify_inproc(eventname, node=self, rep=rep)
316316
elif eventname == "collectionfinish":
317317
self.notify_inproc(eventname, node=self, ids=kwargs['ids'])
318+
elif eventname == "logwarning":
319+
self.notify_inproc(eventname, message=kwargs['message'],
320+
code=kwargs['code'], nodeid=kwargs['nodeid'],
321+
fslocation=kwargs['nodeid'])
318322
else:
319323
raise ValueError("unknown event: %s" % (eventname,))
320324
except KeyboardInterrupt:

0 commit comments

Comments
 (0)