From 02754d84d3d9921ccdd29ac3902a8210612f2a08 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 9 Aug 2017 07:31:09 -0300 Subject: [PATCH 1/5] Remove __multicall__ from pytest_sessionfinish --- xdist/remote.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xdist/remote.py b/xdist/remote.py index 7c5ded7..5661f17 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -8,7 +8,7 @@ import sys import os - +import pytest class SlaveInteractor: def __init__(self, config, channel): @@ -33,11 +33,11 @@ class SlaveInteractor: slaveinfo = getinfodict() self.sendevent("slaveready", slaveinfo=slaveinfo) - def pytest_sessionfinish(self, __multicall__, exitstatus): + @pytest.hookimpl(hookwrapper=True) + def pytest_sessionfinish(self, exitstatus): self.config.slaveoutput['exitstatus'] = exitstatus - res = __multicall__.execute() + yield self.sendevent("slavefinished", slaveoutput=self.config.slaveoutput) - return res def pytest_collection(self, session): self.sendevent("collectionstart") From d0474076e9f6180bb0e6881125533e72abda5bc3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 9 Aug 2017 07:32:14 -0300 Subject: [PATCH 2/5] Transfer warnings from workers to master Fix #92 --- changelog/92.feature | 1 + testing/acceptance_test.py | 12 ++++++++++++ xdist/dsession.py | 5 +++++ xdist/remote.py | 3 +++ xdist/slavemanage.py | 4 ++++ 5 files changed, 25 insertions(+) create mode 100644 changelog/92.feature 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: From c31ec8b222effc34e3a6a08e7ee607a18fb56882 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 9 Aug 2017 07:57:39 -0300 Subject: [PATCH 3/5] Skip test_logwarning on pytest versions older than 3.1 --- testing/acceptance_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index ae02723..7349273 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -340,6 +340,7 @@ class TestTerminalReporting: ]) @pytest.mark.parametrize('n', ['-n0', '-n1']) + @pytest.mark.skipif(pytest.__version__ < "3.1", reason='pytest warnings requires >= 3.1') def test_logwarning(self, testdir, n): testdir.makepyfile(""" import warnings From 0987356f642e25b91dd3e48e84b459b0f13add31 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 9 Aug 2017 08:54:23 -0300 Subject: [PATCH 4/5] Increase max-line-size for flake8 to 100 and fix other flake errors --- setup.cfg | 3 +++ xdist/remote.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ed8a958..36f3f4d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,6 @@ universal = 1 [metadata] license_file = LICENSE + +[flake8] +max-line-length = 100 diff --git a/xdist/remote.py b/xdist/remote.py index 0f008f2..f976060 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -10,6 +10,7 @@ import sys import os import pytest + class SlaveInteractor: def __init__(self, config, channel): self.config = config @@ -97,7 +98,8 @@ class SlaveInteractor: self.sendevent("collectreport", data=data) def pytest_logwarning(self, message, code, nodeid, fslocation): - self.sendevent("logwarning", message=message, code=code, nodeid=nodeid, fslocation=fslocation) + self.sendevent("logwarning", message=message, code=code, nodeid=nodeid, + fslocation=fslocation) def serialize_report(rep): From fb6a6872a0bd5cac7358ac73409e01b04fb20484 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 9 Aug 2017 10:09:29 -0300 Subject: [PATCH 5/5] Use pkg_resources to parse the actual pytest version --- testing/acceptance_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 7349273..bc71b8c 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -340,8 +340,10 @@ class TestTerminalReporting: ]) @pytest.mark.parametrize('n', ['-n0', '-n1']) - @pytest.mark.skipif(pytest.__version__ < "3.1", reason='pytest warnings requires >= 3.1') def test_logwarning(self, testdir, n): + from pkg_resources import parse_version + if parse_version(pytest.__version__) < parse_version('3.1'): + pytest.skip('pytest warnings requires >= 3.1') testdir.makepyfile(""" import warnings def test_func():