Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}