Skip to content

Commit 459e10b

Browse files
authored
Merge pull request #9133 from okken/9113_deselected_assert_outcomes
2 parents d0bdc26 + 6d6cfd8 commit 459e10b

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

changelog/9113.feature.rst

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def assert_outcomes(
588588
xpassed: int = 0,
589589
xfailed: int = 0,
590590
warnings: int = 0,
591+
deselected: 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."""
@@ -604,6 +605,7 @@ def assert_outcomes(
604605
xpassed=xpassed,
605606
xfailed=xfailed,
606607
warnings=warnings,
608+
deselected=deselected,
607609
)
608610

609611

src/_pytest/pytester_assertions.py

Lines changed: 3 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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)