diff --git a/changelog/9113.feature.rst b/changelog/9113.feature.rst new file mode 100644 index 000000000..f16e6ea63 --- /dev/null +++ b/changelog/9113.feature.rst @@ -0,0 +1,2 @@ +:class:`RunResult <_pytest.pytester.RunResult>` method :meth:`assert_outcomes <_pytest.pytester.RunResult.assert_outcomes>` now accepts a +``deselected`` argument to assert the total number of deselected tests. diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index c8258d4b6..9933f7946 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -589,6 +589,7 @@ class RunResult: xpassed: int = 0, xfailed: int = 0, warnings: int = 0, + deselected: int = 0, ) -> None: """Assert that the specified outcomes appear with the respective numbers (0 means it didn't occur) in the text output from a test run.""" @@ -605,6 +606,7 @@ class RunResult: xpassed=xpassed, xfailed=xfailed, warnings=warnings, + deselected=deselected, ) diff --git a/src/_pytest/pytester_assertions.py b/src/_pytest/pytester_assertions.py index 45aa41c5a..6a5aabece 100644 --- a/src/_pytest/pytester_assertions.py +++ b/src/_pytest/pytester_assertions.py @@ -43,6 +43,7 @@ def assert_outcomes( xpassed: int = 0, xfailed: int = 0, warnings: int = 0, + deselected: int = 0, ) -> None: """Assert that the specified outcomes appear with the respective numbers (0 means it didn't occur) in the text output from a test run.""" @@ -56,6 +57,7 @@ def assert_outcomes( "xpassed": outcomes.get("xpassed", 0), "xfailed": outcomes.get("xfailed", 0), "warnings": outcomes.get("warnings", 0), + "deselected": outcomes.get("deselected", 0), } expected = { "passed": passed, @@ -65,5 +67,6 @@ def assert_outcomes( "xpassed": xpassed, "xfailed": xfailed, "warnings": warnings, + "deselected": deselected, } assert obtained == expected diff --git a/testing/test_pytester.py b/testing/test_pytester.py index b0a94223c..d9c97c896 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -861,3 +861,17 @@ def test_pytester_assert_outcomes_warnings(pytester: Pytester) -> None: ) result = pytester.runpytest() result.assert_outcomes(passed=1, warnings=1) + + +def test_pytester_outcomes_deselected(pytester: Pytester) -> None: + pytester.makepyfile( + """ + def test_one(): + pass + + def test_two(): + pass + """ + ) + result = pytester.runpytest("-k", "test_one") + result.assert_outcomes(passed=1, deselected=1)