pytester: Hookrecorder: improve assertoutcome
Before: def assertoutcome(self, passed: int = 0, skipped: int = 0, failed: int = 0) -> None: realpassed, realskipped, realfailed = self.listoutcomes() assert passed == len(realpassed) > assert skipped == len(realskipped) E assert 1 == 0 E + where 0 = len([]) After: > reprec = testdir.inline_run(testpath, "-s") E AssertionError: ([], [], [<TestReport 'nodeid' when='call' outcome='failed'>]) E assert {'failed': 1, 'passed': 0, 'skipped': 0} == {'failed': 0, 'passed': 0, 'skipped': 1}
This commit is contained in:
parent
e2022a6d48
commit
6ddf7c3d42
|
@ -0,0 +1 @@
|
|||
Improved failure reporting with pytester's ``Hookrecorder.assertoutcome``.
|
|
@ -332,10 +332,17 @@ class HookRecorder:
|
|||
return [len(x) for x in self.listoutcomes()]
|
||||
|
||||
def assertoutcome(self, passed: int = 0, skipped: int = 0, failed: int = 0) -> None:
|
||||
realpassed, realskipped, realfailed = self.listoutcomes()
|
||||
assert passed == len(realpassed)
|
||||
assert skipped == len(realskipped)
|
||||
assert failed == len(realfailed)
|
||||
__tracebackhide__ = True
|
||||
|
||||
outcomes = self.listoutcomes()
|
||||
realpassed, realskipped, realfailed = outcomes
|
||||
obtained = {
|
||||
"passed": len(realpassed),
|
||||
"skipped": len(realskipped),
|
||||
"failed": len(realfailed),
|
||||
}
|
||||
expected = {"passed": passed, "skipped": skipped, "failed": failed}
|
||||
assert obtained == expected, outcomes
|
||||
|
||||
def clear(self) -> None:
|
||||
self.calls[:] = []
|
||||
|
|
|
@ -70,7 +70,14 @@ class TestImportHookInstallation:
|
|||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess()
|
||||
result.stdout.fnmatch_lines(["*assert 1 == 0*"])
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"E * AssertionError: ([[][]], [[][]], [[]<TestReport *>[]])*",
|
||||
"E * assert"
|
||||
" {'failed': 1, 'passed': 0, 'skipped': 0} =="
|
||||
" {'failed': 0, 'passed': 1, 'skipped': 0}",
|
||||
]
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("mode", ["plain", "rewrite"])
|
||||
def test_pytest_plugins_rewrite(self, testdir, mode):
|
||||
|
|
Loading…
Reference in New Issue