Skip to content

Commit

Permalink
Merge pull request #6382 from blueyed/fix-parseoutcomes
Browse files Browse the repository at this point in the history
Fix `RunResult.parseoutcomes` (follow-up to #6353)
  • Loading branch information
blueyed authored Jan 3, 2020
2 parents 3b60e36 + 1c0242d commit 7aac48c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion changelog/6532.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix problem with ``testdir`` not recognizing errors correctly in runs with a single test.
Fix parsing of outcomes containing multiple errors with ``testdir`` results (regression in 5.3.0).
13 changes: 9 additions & 4 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,14 @@ def parseoutcomes(self) -> Dict[str, int]:
for line in reversed(self.outlines):
if rex_session_duration.search(line):
outcomes = rex_outcome.findall(line)
return {noun: int(count) for (count, noun) in outcomes}

raise ValueError("Pytest terminal summary report not found")
ret = {noun: int(count) for (count, noun) in outcomes}
break
else:
raise ValueError("Pytest terminal summary report not found")
if "errors" in ret:
assert "error" not in ret
ret["error"] = ret.pop("errors")
return ret

def assert_outcomes(
self,
Expand All @@ -456,7 +461,7 @@ def assert_outcomes(
"passed": d.get("passed", 0),
"skipped": d.get("skipped", 0),
"failed": d.get("failed", 0),
"error": d.get("error", 0) + d.get("errors", 0),
"error": d.get("error", 0),
"xpassed": d.get("xpassed", 0),
"xfailed": d.get("xfailed", 0),
}
Expand Down
12 changes: 7 additions & 5 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,9 @@ def test_run_result_repr():
)


def test_run_pytester_with_single_test(testdir):
testcode = """
def test_testdir_outcomes_with_multiple_errors(testdir):
p1 = testdir.makepyfile(
"""
import pytest
@pytest.fixture
Expand All @@ -698,7 +699,8 @@ def test_error1(bad_fixture):
def test_error2(bad_fixture):
pass
"""

testdir.makepyfile(testcode)
result = testdir.runpytest()
)
result = testdir.runpytest(str(p1))
result.assert_outcomes(error=2)

assert result.parseoutcomes() == {"error": 2}

0 comments on commit 7aac48c

Please sign in to comment.