terminal: summary_passes: handle teardown sections
Fixes https://github.com/pytest-dev/pytest/issues/2780.
This commit is contained in:
parent
622995a501
commit
61d04d3084
|
@ -0,0 +1 @@
|
|||
Captured output during teardown is shown with ``-rP``.
|
|
@ -833,8 +833,20 @@ class TerminalReporter:
|
|||
msg = self._getfailureheadline(rep)
|
||||
self.write_sep("_", msg, green=True, bold=True)
|
||||
self._outrep_summary(rep)
|
||||
self._handle_teardown_sections(rep.nodeid)
|
||||
|
||||
def print_teardown_sections(self, rep):
|
||||
def _get_teardown_reports(self, nodeid: str) -> List[TestReport]:
|
||||
return [
|
||||
report
|
||||
for report in self.getreports("")
|
||||
if report.when == "teardown" and report.nodeid == nodeid
|
||||
]
|
||||
|
||||
def _handle_teardown_sections(self, nodeid: str) -> None:
|
||||
for report in self._get_teardown_reports(nodeid):
|
||||
self.print_teardown_sections(report)
|
||||
|
||||
def print_teardown_sections(self, rep: TestReport) -> None:
|
||||
showcapture = self.config.option.showcapture
|
||||
if showcapture == "no":
|
||||
return
|
||||
|
@ -858,17 +870,11 @@ class TerminalReporter:
|
|||
line = self._getcrashline(rep)
|
||||
self.write_line(line)
|
||||
else:
|
||||
teardown_sections = {}
|
||||
for report in self.getreports(""):
|
||||
if report.when == "teardown":
|
||||
teardown_sections.setdefault(report.nodeid, []).append(report)
|
||||
|
||||
for rep in reports:
|
||||
msg = self._getfailureheadline(rep)
|
||||
self.write_sep("_", msg, red=True, bold=True)
|
||||
self._outrep_summary(rep)
|
||||
for report in teardown_sections.get(rep.nodeid, []):
|
||||
self.print_teardown_sections(report)
|
||||
self._handle_teardown_sections(rep.nodeid)
|
||||
|
||||
def summary_errors(self):
|
||||
if self.config.option.tbstyle != "no":
|
||||
|
|
|
@ -790,8 +790,15 @@ def test_pass_reporting_on_fail(testdir):
|
|||
def test_pass_output_reporting(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def setup_module():
|
||||
print("setup_module")
|
||||
|
||||
def teardown_module():
|
||||
print("teardown_module")
|
||||
|
||||
def test_pass_has_output():
|
||||
print("Four score and seven years ago...")
|
||||
|
||||
def test_pass_no_output():
|
||||
pass
|
||||
"""
|
||||
|
@ -806,8 +813,12 @@ def test_pass_output_reporting(testdir):
|
|||
[
|
||||
"*= PASSES =*",
|
||||
"*_ test_pass_has_output _*",
|
||||
"*- Captured stdout setup -*",
|
||||
"setup_module",
|
||||
"*- Captured stdout call -*",
|
||||
"Four score and seven years ago...",
|
||||
"*- Captured stdout teardown -*",
|
||||
"teardown_module",
|
||||
"*= short test summary info =*",
|
||||
"PASSED test_pass_output_reporting.py::test_pass_has_output",
|
||||
"PASSED test_pass_output_reporting.py::test_pass_no_output",
|
||||
|
|
Loading…
Reference in New Issue