Skip to content

Commit f91bf48

Browse files
authored
Merge pull request #6176 from blueyed/assertoutcome
pytester: Hookrecorder: improve assertoutcome
2 parents a6e10cc + 6ddf7c3 commit f91bf48

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

changelog/6176.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved failure reporting with pytester's ``Hookrecorder.assertoutcome``.

src/_pytest/pytester.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,17 @@ def countoutcomes(self) -> List[int]:
332332
return [len(x) for x in self.listoutcomes()]
333333

334334
def assertoutcome(self, passed: int = 0, skipped: int = 0, failed: int = 0) -> None:
335-
realpassed, realskipped, realfailed = self.listoutcomes()
336-
assert passed == len(realpassed)
337-
assert skipped == len(realskipped)
338-
assert failed == len(realfailed)
335+
__tracebackhide__ = True
336+
337+
outcomes = self.listoutcomes()
338+
realpassed, realskipped, realfailed = outcomes
339+
obtained = {
340+
"passed": len(realpassed),
341+
"skipped": len(realskipped),
342+
"failed": len(realfailed),
343+
}
344+
expected = {"passed": passed, "skipped": skipped, "failed": failed}
345+
assert obtained == expected, outcomes
339346

340347
def clear(self) -> None:
341348
self.calls[:] = []

testing/test_assertion.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ def test_dummy_failure(testdir): # how meta!
7070
"""
7171
)
7272
result = testdir.runpytest_subprocess()
73-
result.stdout.fnmatch_lines(["*assert 1 == 0*"])
73+
result.stdout.fnmatch_lines(
74+
[
75+
"E * AssertionError: ([[][]], [[][]], [[]<TestReport *>[]])*",
76+
"E * assert"
77+
" {'failed': 1, 'passed': 0, 'skipped': 0} =="
78+
" {'failed': 0, 'passed': 1, 'skipped': 0}",
79+
]
80+
)
7481

7582
@pytest.mark.parametrize("mode", ["plain", "rewrite"])
7683
def test_pytest_plugins_rewrite(self, testdir, mode):

0 commit comments

Comments
 (0)