Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a deselected parameter to assert_outcomes(), closes #9113 #9133

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/9113.feature.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,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."""
Expand All @@ -605,6 +606,7 @@ def assert_outcomes(
xpassed=xpassed,
xfailed=xfailed,
warnings=warnings,
deselected=deselected,
)


Expand Down
3 changes: 3 additions & 0 deletions src/_pytest/pytester_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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,
Expand All @@ -65,5 +67,6 @@ def assert_outcomes(
"xpassed": xpassed,
"xfailed": xfailed,
"warnings": warnings,
"deselected": deselected,
}
assert obtained == expected
14 changes: 14 additions & 0 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,3 +861,17 @@ def test_with_warning():
)
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)