Skip to content

Warnings support #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/92.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warnings are now properly transferred from workers to the master node.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ universal = 1

[metadata]
license_file = LICENSE

[flake8]
max-line-length = 100
15 changes: 15 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,21 @@ def test_func():
"E assert 0",
])

@pytest.mark.parametrize('n', ['-n0', '-n1'])
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():
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("""
Expand Down
5 changes: 5 additions & 0 deletions xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ def slave_collectreport(self, node, rep):
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.

Expand Down
11 changes: 8 additions & 3 deletions xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import sys
import os
import pytest


class SlaveInteractor:
Expand All @@ -33,11 +34,11 @@ def pytest_sessionstart(self, session):
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")
Expand Down Expand Up @@ -96,6 +97,10 @@ def pytest_collectreport(self, report):
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):
Expand Down
4 changes: 4 additions & 0 deletions xdist/slavemanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def process_from_remote(self, eventcall): # noqa too complex
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:
Expand Down