Skip to content

Commit

Permalink
Added support for xfailed and xpassed outcomes to the ``pytester.RunR…
Browse files Browse the repository at this point in the history
…esult.assert_outcomes`` signature.
  • Loading branch information
wimglenn committed Aug 20, 2018
1 parent 28aff05 commit 1d3cb52
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Vitaly Lashmanov
Vlad Dragos
Wil Cooley
William Lee
Wim Glenn
Wouter van Ackooy
Xuan Luong
Xuecong Liao
Expand Down
1 change: 1 addition & 0 deletions changelog/3837.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for 'xfailed' and 'xpassed' outcomes to the ``pytester.RunResult.assert_outcomes`` signature.
16 changes: 12 additions & 4 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def parseoutcomes(self):
return d
raise ValueError("Pytest terminal report not found")

def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0):
def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0, xpassed=0, xfailed=0):
"""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 @@ -417,10 +417,18 @@ def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0):
"skipped": d.get("skipped", 0),
"failed": d.get("failed", 0),
"error": d.get("error", 0),
"xpassed": d.get("xpassed", 0),
"xfailed": d.get("xfailed", 0),
}
assert obtained == dict(
passed=passed, skipped=skipped, failed=failed, error=error
)
expected = {
"passed": passed,
"skipped": skipped,
"failed": failed,
"error": error,
"xpassed": xpassed,
"xfailed": xfailed,
}
assert obtained == expected


class CwdSnapshot(object):
Expand Down
51 changes: 51 additions & 0 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,57 @@ def test_hello(testdir):
result.assert_outcomes(passed=1)


def test_runresult_assertion_on_xfail(testdir):
testdir.makepyfile(
"""
import pytest
pytest_plugins = "pytester"
@pytest.mark.xfail
def test_potato():
assert False
"""
)
result = testdir.runpytest()
result.assert_outcomes(xfailed=1)
assert result.ret == 0


def test_runresult_assertion_on_xpassed(testdir):
testdir.makepyfile(
"""
import pytest
pytest_plugins = "pytester"
@pytest.mark.xfail
def test_potato():
assert True
"""
)
result = testdir.runpytest()
result.assert_outcomes(xpassed=1)
assert result.ret == 0


def test_xpassed_with_strict_is_considered_a_failure(testdir):
testdir.makepyfile(
"""
import pytest
pytest_plugins = "pytester"
@pytest.mark.xfail(strict=True)
def test_potato():
assert True
"""
)
result = testdir.runpytest()
result.assert_outcomes(failed=1)
assert result.ret != 0


def make_holder():
class apiclass(object):
def pytest_xyz(self, arg):
Expand Down

0 comments on commit 1d3cb52

Please sign in to comment.