@@ -401,7 +401,7 @@ def test_func():
401
401
)
402
402
403
403
@pytest .mark .parametrize ("n" , ["-n0" , "-n1" ])
404
- @pytest .mark .parametrize ("warn_type" , ["pytest" , "builtin" , "invalid" ])
404
+ @pytest .mark .parametrize ("warn_type" , ["pytest" , "builtin" ])
405
405
def test_warnings (self , testdir , n , warn_type ):
406
406
from pkg_resources import parse_version
407
407
@@ -413,8 +413,6 @@ def test_warnings(self, testdir, n, warn_type):
413
413
elif warn_type == "pytest" :
414
414
warn_code = """request.config.warn('', 'this is a warning',
415
415
fslocation=py.path.local())"""
416
- elif warn_type == "invalid" :
417
- warn_code = "msg = UserWarning('this is a warning'); msg.args = (); warnings.warn(msg)"
418
416
else :
419
417
assert False
420
418
testdir .makepyfile (
@@ -431,6 +429,35 @@ def test_func(request):
431
429
result = testdir .runpytest (n )
432
430
result .stdout .fnmatch_lines (["*this is a warning*" , "*1 passed, 1 warnings*" ])
433
431
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
+
434
461
def test_logfinish_hook (self , testdir ):
435
462
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
436
463
from _pytest import hookspec
0 commit comments