Skip to content

Commit 6d6cfd8

Browse files
committed
Add a deselected parameter to assert_outcomes()
1 parent 7720154 commit 6d6cfd8

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

changelog/9113.feature.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:class:`RunResult <_pytest.pytester.RunResult>` method :meth:`assert_outcomes <_pytest.pytester.RunResult.assert_outcomes>` now accepts a
2+
``deselected`` argument to assert the total number of deselected tests.

src/_pytest/pytester.py

+2
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ def assert_outcomes(
589589
xpassed: int = 0,
590590
xfailed: int = 0,
591591
warnings: int = 0,
592+
deselected: int = 0,
592593
) -> None:
593594
"""Assert that the specified outcomes appear with the respective
594595
numbers (0 means it didn't occur) in the text output from a test run."""
@@ -605,6 +606,7 @@ def assert_outcomes(
605606
xpassed=xpassed,
606607
xfailed=xfailed,
607608
warnings=warnings,
609+
deselected=deselected,
608610
)
609611

610612

src/_pytest/pytester_assertions.py

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def assert_outcomes(
4343
xpassed: int = 0,
4444
xfailed: int = 0,
4545
warnings: int = 0,
46+
deselected: int = 0,
4647
) -> None:
4748
"""Assert that the specified outcomes appear with the respective
4849
numbers (0 means it didn't occur) in the text output from a test run."""
@@ -56,6 +57,7 @@ def assert_outcomes(
5657
"xpassed": outcomes.get("xpassed", 0),
5758
"xfailed": outcomes.get("xfailed", 0),
5859
"warnings": outcomes.get("warnings", 0),
60+
"deselected": outcomes.get("deselected", 0),
5961
}
6062
expected = {
6163
"passed": passed,
@@ -65,5 +67,6 @@ def assert_outcomes(
6567
"xpassed": xpassed,
6668
"xfailed": xfailed,
6769
"warnings": warnings,
70+
"deselected": deselected,
6871
}
6972
assert obtained == expected

testing/test_pytester.py

+14
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,17 @@ def test_with_warning():
861861
)
862862
result = pytester.runpytest()
863863
result.assert_outcomes(passed=1, warnings=1)
864+
865+
866+
def test_pytester_outcomes_deselected(pytester: Pytester) -> None:
867+
pytester.makepyfile(
868+
"""
869+
def test_one():
870+
pass
871+
872+
def test_two():
873+
pass
874+
"""
875+
)
876+
result = pytester.runpytest("-k", "test_one")
877+
result.assert_outcomes(passed=1, deselected=1)

0 commit comments

Comments
 (0)