Skip to content

Commit

Permalink
terminal: summary_passes: handle teardown sections
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Jan 11, 2020
1 parent 622995a commit 61d04d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/2780.bugfix.rst
@@ -0,0 +1 @@
Captured output during teardown is shown with ``-rP``.
22 changes: 14 additions & 8 deletions src/_pytest/terminal.py
Expand Up @@ -833,8 +833,20 @@ def summary_passes(self):
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
Expand All @@ -858,17 +870,11 @@ def summary_failures(self):
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":
Expand Down
11 changes: 11 additions & 0 deletions testing/test_terminal.py
Expand Up @@ -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
"""
Expand All @@ -806,8 +813,12 @@ def test_pass_no_output():
[
"*= 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",
Expand Down

0 comments on commit 61d04d3

Please sign in to comment.