@@ -400,64 +400,6 @@ def test_func():
400
400
]
401
401
)
402
402
403
- @pytest .mark .parametrize ("n" , ["-n0" , "-n1" ])
404
- @pytest .mark .parametrize ("warn_type" , ["pytest" , "builtin" ])
405
- def test_warnings (self , testdir , n , warn_type ):
406
- from pkg_resources import parse_version
407
-
408
- if parse_version (pytest .__version__ ) < parse_version ("3.1" ):
409
- pytest .skip ("pytest warnings requires >= 3.1" )
410
-
411
- if warn_type == "builtin" :
412
- warn_code = """warnings.warn(UserWarning('this is a warning'))"""
413
- elif warn_type == "pytest" :
414
- warn_code = """request.config.warn('', 'this is a warning',
415
- fslocation=py.path.local())"""
416
- else :
417
- assert False
418
- testdir .makepyfile (
419
- """
420
- import warnings, py, pytest
421
-
422
- @pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
423
- def test_func(request):
424
- {warn_code}
425
- """ .format (
426
- warn_code = warn_code
427
- )
428
- )
429
- result = testdir .runpytest (n )
430
- result .stdout .fnmatch_lines (["*this is a warning*" , "*1 passed, 1 warnings*" ])
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
-
461
403
def test_logfinish_hook (self , testdir ):
462
404
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
463
405
from _pytest import hookspec
@@ -765,6 +707,66 @@ def test_ok():
765
707
result .stdout .fnmatch_lines ("*1 passed*" )
766
708
767
709
710
+ class TestWarnings :
711
+ @pytest .fixture (autouse = True )
712
+ def skip_if_unsupported_pytest_version (self ):
713
+ """Skip tests of this class if we are running in a pytest version which does not
714
+ support warnings yet.
715
+ """
716
+ from pkg_resources import parse_version
717
+
718
+ if parse_version (pytest .__version__ ) < parse_version ("3.1" ):
719
+ pytest .skip ("pytest warnings requires >= 3.1" )
720
+
721
+ @pytest .mark .parametrize ("n" , ["-n0" , "-n1" ])
722
+ @pytest .mark .parametrize ("warn_type" , ["pytest" , "builtin" ])
723
+ def test_warnings (self , testdir , n , warn_type ):
724
+ if warn_type == "builtin" :
725
+ warn_code = """warnings.warn(UserWarning('this is a warning'))"""
726
+ elif warn_type == "pytest" :
727
+ warn_code = """request.config.warn('', 'this is a warning',
728
+ fslocation=py.path.local())"""
729
+ else :
730
+ assert False
731
+ testdir .makepyfile (
732
+ """
733
+ import warnings, py, pytest
734
+
735
+ @pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
736
+ def test_func(request):
737
+ {warn_code}
738
+ """ .format (
739
+ warn_code = warn_code
740
+ )
741
+ )
742
+ result = testdir .runpytest (n )
743
+ result .stdout .fnmatch_lines (["*this is a warning*" , "*1 passed, 1 warnings*" ])
744
+
745
+ @pytest .mark .parametrize ("n" , ["-n0" , "-n1" ])
746
+ def test_custom_subclass (self , testdir , n ):
747
+ """Check that warning subclasses that don't honor the args attribute don't break
748
+ pytest-xdist (#344)
749
+ """
750
+ testdir .makepyfile (
751
+ """
752
+ import warnings, py, pytest
753
+
754
+ class MyWarning(UserWarning):
755
+
756
+ def __init__(self, p1, p2):
757
+ self.p1 = p1
758
+ self.p2 = p2
759
+ self.args = ()
760
+
761
+ def test_func(request):
762
+ warnings.warn(MyWarning("foo", 1))
763
+ """
764
+ )
765
+ testdir .syspathinsert ()
766
+ result = testdir .runpytest (n )
767
+ result .stdout .fnmatch_lines (["*MyWarning*" , "*1 passed, 1 warnings*" ])
768
+
769
+
768
770
class TestNodeFailure :
769
771
def test_load_single (self , testdir ):
770
772
f = testdir .makepyfile (
0 commit comments