File tree Expand file tree Collapse file tree 5 files changed +22
-1
lines changed Expand file tree Collapse file tree 5 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ :class: `RunResult <_pytest.pytester.RunResult> ` method :meth: `assert_outcomes <_pytest.pytester.RunResult.assert_outcomes> ` now accepts a
2
+ ``warnings `` argument to assert the total number of warnings captured.
Original file line number Diff line number Diff line change @@ -588,6 +588,7 @@ def assert_outcomes(
588
588
errors : int = 0 ,
589
589
xpassed : int = 0 ,
590
590
xfailed : int = 0 ,
591
+ warnings : int = 0 ,
591
592
) -> None :
592
593
"""Assert that the specified outcomes appear with the respective
593
594
numbers (0 means it didn't occur) in the text output from a test run."""
@@ -603,6 +604,7 @@ def assert_outcomes(
603
604
errors = errors ,
604
605
xpassed = xpassed ,
605
606
xfailed = xfailed ,
607
+ warnings = warnings ,
606
608
)
607
609
608
610
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ def assert_outcomes(
42
42
errors : int = 0 ,
43
43
xpassed : int = 0 ,
44
44
xfailed : int = 0 ,
45
+ warnings : int = 0 ,
45
46
) -> None :
46
47
"""Assert that the specified outcomes appear with the respective
47
48
numbers (0 means it didn't occur) in the text output from a test run."""
@@ -54,6 +55,7 @@ def assert_outcomes(
54
55
"errors" : outcomes .get ("errors" , 0 ),
55
56
"xpassed" : outcomes .get ("xpassed" , 0 ),
56
57
"xfailed" : outcomes .get ("xfailed" , 0 ),
58
+ "warnings" : outcomes .get ("warnings" , 0 ),
57
59
}
58
60
expected = {
59
61
"passed" : passed ,
@@ -62,5 +64,6 @@ def assert_outcomes(
62
64
"errors" : errors ,
63
65
"xpassed" : xpassed ,
64
66
"xfailed" : xfailed ,
67
+ "warnings" : warnings ,
65
68
}
66
69
assert obtained == expected
Original file line number Diff line number Diff line change @@ -335,7 +335,7 @@ def test_failing():
335
335
"""
336
336
)
337
337
result = pytester .runpytest (p )
338
- result .assert_outcomes (skipped = 1 )
338
+ result .assert_outcomes (skipped = 1 , warnings = 1 )
339
339
340
340
341
341
def test_SkipTest_in_test (pytester : Pytester ) -> None :
Original file line number Diff line number Diff line change @@ -847,3 +847,17 @@ def test_testdir_makefile_ext_empty_string_makes_file(testdir) -> None:
847
847
"""For backwards compat #8192"""
848
848
p1 = testdir .makefile ("" , "" )
849
849
assert "test_testdir_makefile" in str (p1 )
850
+
851
+
852
+ @pytest .mark .filterwarnings ("default" )
853
+ def test_pytester_assert_outcomes_warnings (pytester : Pytester ) -> None :
854
+ pytester .makepyfile (
855
+ """
856
+ import warnings
857
+
858
+ def test_with_warning():
859
+ warnings.warn(UserWarning("some custom warning"))
860
+ """
861
+ )
862
+ result = pytester .runpytest ()
863
+ result .assert_outcomes (passed = 1 , warnings = 1 )
You can’t perform that action at this time.
0 commit comments