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(
588588 errors : int = 0 ,
589589 xpassed : int = 0 ,
590590 xfailed : int = 0 ,
591+ warnings : int = 0 ,
591592 ) -> None :
592593 """Assert that the specified outcomes appear with the respective
593594 numbers (0 means it didn't occur) in the text output from a test run."""
@@ -603,6 +604,7 @@ def assert_outcomes(
603604 errors = errors ,
604605 xpassed = xpassed ,
605606 xfailed = xfailed ,
607+ warnings = warnings ,
606608 )
607609
608610
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ def assert_outcomes(
4242 errors : int = 0 ,
4343 xpassed : int = 0 ,
4444 xfailed : int = 0 ,
45+ warnings : int = 0 ,
4546) -> None :
4647 """Assert that the specified outcomes appear with the respective
4748 numbers (0 means it didn't occur) in the text output from a test run."""
@@ -54,6 +55,7 @@ def assert_outcomes(
5455 "errors" : outcomes .get ("errors" , 0 ),
5556 "xpassed" : outcomes .get ("xpassed" , 0 ),
5657 "xfailed" : outcomes .get ("xfailed" , 0 ),
58+ "warnings" : outcomes .get ("warnings" , 0 ),
5759 }
5860 expected = {
5961 "passed" : passed ,
@@ -62,5 +64,6 @@ def assert_outcomes(
6264 "errors" : errors ,
6365 "xpassed" : xpassed ,
6466 "xfailed" : xfailed ,
67+ "warnings" : warnings ,
6568 }
6669 assert obtained == expected
Original file line number Diff line number Diff line change @@ -335,7 +335,7 @@ def test_failing():
335335 """
336336 )
337337 result = pytester .runpytest (p )
338- result .assert_outcomes (skipped = 1 )
338+ result .assert_outcomes (skipped = 1 , warnings = 1 )
339339
340340
341341def 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:
847847 """For backwards compat #8192"""
848848 p1 = testdir .makefile ("" , "" )
849849 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