Skip to content

Commit

Permalink
Fix crash when transferring internal pytest warnings from workers to …
Browse files Browse the repository at this point in the history
…the master node

Fix pytest-dev#214
  • Loading branch information
nicoddemus committed Aug 9, 2017
1 parent a54f531 commit 20a1b9e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/214.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when transferring internal pytest warnings from workers to the master node.
20 changes: 15 additions & 5 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,28 @@ def test_func():
])

@pytest.mark.parametrize('n', ['-n0', '-n1'])
def test_logwarning(self, testdir, n):
@pytest.mark.parametrize('warn_type', ['pytest', 'builtin'])
def test_logwarning(self, testdir, n, warn_type):
from pkg_resources import parse_version
if parse_version(pytest.__version__) < parse_version('3.1'):
pytest.skip('pytest warnings requires >= 3.1')

if warn_type == 'builtin':
warn_code = """warnings.warn(UserWarning('this is a warning'))"""
elif warn_type == 'pytest':
warn_code = """request.config.warn('', 'this is a warning',
fslocation=py.path.local())"""
else:
assert False
testdir.makepyfile("""
import warnings
def test_func():
warnings.warn('this is a warning')
""")
import warnings, py
def test_func(request):
{warn_code}
""".format(warn_code=warn_code))
result = testdir.runpytest(n)
result.stdout.fnmatch_lines([
"*this is a warning*",
"*1 passed, 1 warnings*",
])


Expand Down
2 changes: 1 addition & 1 deletion xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def pytest_collectreport(self, report):

def pytest_logwarning(self, message, code, nodeid, fslocation):
self.sendevent("logwarning", message=message, code=code, nodeid=nodeid,
fslocation=fslocation)
fslocation=str(fslocation))


def serialize_report(rep):
Expand Down

0 comments on commit 20a1b9e

Please sign in to comment.