diff --git a/changelog/92.feature b/changelog/92.feature new file mode 100644 index 0000000..8f950c5 --- /dev/null +++ b/changelog/92.feature @@ -0,0 +1 @@ +Warnings are now properly transferred from workers to the master node. diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 557464f..ae02723 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -339,6 +339,18 @@ class TestTerminalReporting: "E assert 0", ]) + @pytest.mark.parametrize('n', ['-n0', '-n1']) + def test_logwarning(self, testdir, n): + testdir.makepyfile(""" + import warnings + def test_func(): + warnings.warn('this is a warning') + """) + result = testdir.runpytest(n) + result.stdout.fnmatch_lines([ + "*this is a warning*", + ]) + def test_teardownfails_one_function(testdir): p = testdir.makepyfile(""" diff --git a/xdist/dsession.py b/xdist/dsession.py index 6fe7f79..3700357 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -247,6 +247,11 @@ class DSession: if rep.failed: self._failed_slave_collectreport(node, rep) + def slave_logwarning(self, message, code, nodeid, fslocation): + """Emitted when a node calls the pytest_logwarning hook.""" + kwargs = dict(message=message, code=code, nodeid=nodeid, fslocation=fslocation) + self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs) + def _clone_node(self, node): """Return new node based on an existing one. diff --git a/xdist/remote.py b/xdist/remote.py index 5661f17..0f008f2 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -96,6 +96,9 @@ class SlaveInteractor: data = serialize_report(report) self.sendevent("collectreport", data=data) + def pytest_logwarning(self, message, code, nodeid, fslocation): + self.sendevent("logwarning", message=message, code=code, nodeid=nodeid, fslocation=fslocation) + def serialize_report(rep): def disassembled_report(rep): diff --git a/xdist/slavemanage.py b/xdist/slavemanage.py index 0e45a20..adc7fdd 100644 --- a/xdist/slavemanage.py +++ b/xdist/slavemanage.py @@ -315,6 +315,10 @@ class SlaveController(object): self.notify_inproc(eventname, node=self, rep=rep) elif eventname == "collectionfinish": self.notify_inproc(eventname, node=self, ids=kwargs['ids']) + elif eventname == "logwarning": + self.notify_inproc(eventname, message=kwargs['message'], + code=kwargs['code'], nodeid=kwargs['nodeid'], + fslocation=kwargs['nodeid']) else: raise ValueError("unknown event: %s" % (eventname,)) except KeyboardInterrupt: