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)
|
msg = self._getfailureheadline(rep)
|
||||||
self.write_sep("_", msg, green=True, bold=True)
|
self.write_sep("_", msg, green=True, bold=True)
|
||||||
self._outrep_summary(rep)
|
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
|
showcapture = self.config.option.showcapture
|
||||||
if showcapture == "no":
|
if showcapture == "no":
|
||||||
return
|
return
|
||||||
|
@ -858,17 +870,11 @@ class TerminalReporter:
|
||||||
line = self._getcrashline(rep)
|
line = self._getcrashline(rep)
|
||||||
self.write_line(line)
|
self.write_line(line)
|
||||||
else:
|
else:
|
||||||
teardown_sections = {}
|
|
||||||
for report in self.getreports(""):
|
|
||||||
if report.when == "teardown":
|
|
||||||
teardown_sections.setdefault(report.nodeid, []).append(report)
|
|
||||||
|
|
||||||
for rep in reports:
|
for rep in reports:
|
||||||
msg = self._getfailureheadline(rep)
|
msg = self._getfailureheadline(rep)
|
||||||
self.write_sep("_", msg, red=True, bold=True)
|
self.write_sep("_", msg, red=True, bold=True)
|
||||||
self._outrep_summary(rep)
|
self._outrep_summary(rep)
|
||||||
for report in teardown_sections.get(rep.nodeid, []):
|
self._handle_teardown_sections(rep.nodeid)
|
||||||
self.print_teardown_sections(report)
|
|
||||||
|
|
||||||
def summary_errors(self):
|
def summary_errors(self):
|
||||||
if self.config.option.tbstyle != "no":
|
if self.config.option.tbstyle != "no":
|
||||||
|
|
|
@ -790,8 +790,15 @@ def test_pass_reporting_on_fail(testdir):
|
||||||
def test_pass_output_reporting(testdir):
|
def test_pass_output_reporting(testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
def setup_module():
|
||||||
|
print("setup_module")
|
||||||
|
|
||||||
|
def teardown_module():
|
||||||
|
print("teardown_module")
|
||||||
|
|
||||||
def test_pass_has_output():
|
def test_pass_has_output():
|
||||||
print("Four score and seven years ago...")
|
print("Four score and seven years ago...")
|
||||||
|
|
||||||
def test_pass_no_output():
|
def test_pass_no_output():
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
|
@ -806,8 +813,12 @@ def test_pass_output_reporting(testdir):
|
||||||
[
|
[
|
||||||
"*= PASSES =*",
|
"*= PASSES =*",
|
||||||
"*_ test_pass_has_output _*",
|
"*_ test_pass_has_output _*",
|
||||||
|
"*- Captured stdout setup -*",
|
||||||
|
"setup_module",
|
||||||
"*- Captured stdout call -*",
|
"*- Captured stdout call -*",
|
||||||
"Four score and seven years ago...",
|
"Four score and seven years ago...",
|
||||||
|
"*- Captured stdout teardown -*",
|
||||||
|
"teardown_module",
|
||||||
"*= short test summary info =*",
|
"*= short test summary info =*",
|
||||||
"PASSED test_pass_output_reporting.py::test_pass_has_output",
|
"PASSED test_pass_output_reporting.py::test_pass_has_output",
|
||||||
"PASSED test_pass_output_reporting.py::test_pass_no_output",
|
"PASSED test_pass_output_reporting.py::test_pass_no_output",
|
||||||
|
|
Loading…
Reference in New Issue