Skip to content

Commit b176b37

Browse files
committed
Add a test which reproduces #344 and fix the handling code
Fix #344
1 parent 22e36c9 commit b176b37

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

testing/acceptance_test.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def test_func():
401401
)
402402

403403
@pytest.mark.parametrize("n", ["-n0", "-n1"])
404-
@pytest.mark.parametrize("warn_type", ["pytest", "builtin", "invalid"])
404+
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
405405
def test_warnings(self, testdir, n, warn_type):
406406
from pkg_resources import parse_version
407407

@@ -413,8 +413,6 @@ def test_warnings(self, testdir, n, warn_type):
413413
elif warn_type == "pytest":
414414
warn_code = """request.config.warn('', 'this is a warning',
415415
fslocation=py.path.local())"""
416-
elif warn_type == "invalid":
417-
warn_code = "msg = UserWarning('this is a warning'); msg.args = (); warnings.warn(msg)"
418416
else:
419417
assert False
420418
testdir.makepyfile(
@@ -431,6 +429,35 @@ def test_func(request):
431429
result = testdir.runpytest(n)
432430
result.stdout.fnmatch_lines(["*this is a warning*", "*1 passed, 1 warnings*"])
433431

432+
@pytest.mark.parametrize("n", ["-n0", "-n1"])
433+
def test_custom_subclass(self, testdir, n):
434+
"""Check that warning subclasses that don't honor the args attribute don't break
435+
pytest-xdist (#344)
436+
"""
437+
from pkg_resources import parse_version
438+
439+
if parse_version(pytest.__version__) < parse_version("3.1"):
440+
pytest.skip("pytest warnings requires >= 3.1")
441+
442+
testdir.makepyfile(
443+
"""
444+
import warnings, py, pytest
445+
446+
class MyWarning(UserWarning):
447+
448+
def __init__(self, p1, p2):
449+
self.p1 = p1
450+
self.p2 = p2
451+
self.args = ()
452+
453+
def test_func(request):
454+
warnings.warn(MyWarning("foo", 1))
455+
"""
456+
)
457+
testdir.syspathinsert()
458+
result = testdir.runpytest(n)
459+
result.stdout.fnmatch_lines(["*MyWarning*", "*1 passed, 1 warnings*"])
460+
434461
def test_logfinish_hook(self, testdir):
435462
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
436463
from _pytest import hookspec

xdist/workermanage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def unserialize_warning_message(data):
429429
try:
430430
message = cls(*data["message_args"])
431431
except TypeError:
432-
message_text = "{mod}.{class}: {msg}".format(
432+
message_text = "{mod}.{cls}: {msg}".format(
433433
mod=data["message_module"],
434434
cls=data["message_class_name"],
435435
msg=data["message_str"],

0 commit comments

Comments
 (0)