Skip to content

Commit 7aac48c

Browse files
authored
Merge pull request #6382 from blueyed/fix-parseoutcomes
Fix `RunResult.parseoutcomes` (follow-up to #6353)
2 parents 3b60e36 + 1c0242d commit 7aac48c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

changelog/6532.bugfix.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix problem with ``testdir`` not recognizing errors correctly in runs with a single test.
1+
Fix parsing of outcomes containing multiple errors with ``testdir`` results (regression in 5.3.0).

src/_pytest/pytester.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,14 @@ def parseoutcomes(self) -> Dict[str, int]:
433433
for line in reversed(self.outlines):
434434
if rex_session_duration.search(line):
435435
outcomes = rex_outcome.findall(line)
436-
return {noun: int(count) for (count, noun) in outcomes}
437-
438-
raise ValueError("Pytest terminal summary report not found")
436+
ret = {noun: int(count) for (count, noun) in outcomes}
437+
break
438+
else:
439+
raise ValueError("Pytest terminal summary report not found")
440+
if "errors" in ret:
441+
assert "error" not in ret
442+
ret["error"] = ret.pop("errors")
443+
return ret
439444

440445
def assert_outcomes(
441446
self,
@@ -456,7 +461,7 @@ def assert_outcomes(
456461
"passed": d.get("passed", 0),
457462
"skipped": d.get("skipped", 0),
458463
"failed": d.get("failed", 0),
459-
"error": d.get("error", 0) + d.get("errors", 0),
464+
"error": d.get("error", 0),
460465
"xpassed": d.get("xpassed", 0),
461466
"xfailed": d.get("xfailed", 0),
462467
}

testing/test_pytester.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,9 @@ def test_run_result_repr():
684684
)
685685

686686

687-
def test_run_pytester_with_single_test(testdir):
688-
testcode = """
687+
def test_testdir_outcomes_with_multiple_errors(testdir):
688+
p1 = testdir.makepyfile(
689+
"""
689690
import pytest
690691
691692
@pytest.fixture
@@ -698,7 +699,8 @@ def test_error1(bad_fixture):
698699
def test_error2(bad_fixture):
699700
pass
700701
"""
701-
702-
testdir.makepyfile(testcode)
703-
result = testdir.runpytest()
702+
)
703+
result = testdir.runpytest(str(p1))
704704
result.assert_outcomes(error=2)
705+
706+
assert result.parseoutcomes() == {"error": 2}

0 commit comments

Comments
 (0)