Skip to content

Commit

Permalink
Show "short test summary info" after tracebacks and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Feb 22, 2018
1 parent 54e63b7 commit ede394d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
17 changes: 15 additions & 2 deletions _pytest/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,21 @@ def pytest_report_teststatus(report):
Stops at first non-None result, see :ref:`firstresult` """


def pytest_terminal_summary(terminalreporter, exitstatus):
""" add additional section in terminal summary reporting. """
def pytest_terminal_summary(config, terminalreporter, exitstatus):
"""Add initial section to terminal summary reporting (before errors, failures, warnings, etc).
This hook can be used to enhance terminal reporting before pytest displayes the complete list
of errors with tracebacks, failsures, warnings, etc.
"""


def pytest_terminal_final_summary(config, terminalreporter, exitstatus):
"""Add an additional section to terminal summary reporting after pytest has written
full summary reports.
This hook can be used to enhance terminal reporting after pytest displayes the complete list
of errors with tracebacks, failsures, warnings, etc.
"""


@hookspec(historic=True)
Expand Down
2 changes: 1 addition & 1 deletion _pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def pytest_sessionfinish(self):
time="%.3f" % suite_time_delta, ).unicode(indent=0))
logfile.close()

def pytest_terminal_summary(self, terminalreporter):
def pytest_terminal_final_summary(self, terminalreporter):
terminalreporter.write_sep("-",
"generated xml file: %s" % (self.logfile))

Expand Down
2 changes: 1 addition & 1 deletion _pytest/pastebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def create_new_paste(contents):
return 'bad response: ' + response


def pytest_terminal_summary(terminalreporter):
def pytest_terminal_final_summary(terminalreporter):
import _pytest.config
if terminalreporter.config.option.pastebin != "failed":
return
Expand Down
2 changes: 1 addition & 1 deletion _pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def pytest_report_teststatus(report):
# called by the terminalreporter instance/plugin


def pytest_terminal_summary(terminalreporter):
def pytest_terminal_final_summary(terminalreporter):
tr = terminalreporter
if not tr.reportchars:
# for name in "xfailed skipped failed xpassed":
Expand Down
4 changes: 4 additions & 0 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,15 @@ def pytest_sessionfinish(self, exitstatus):
EXIT_NOTESTSCOLLECTED)
if exitstatus in summary_exit_codes:
self.config.hook.pytest_terminal_summary(terminalreporter=self,
config=self.config,
exitstatus=exitstatus)
self.summary_errors()
self.summary_failures()
self.summary_warnings()
self.summary_passes()
self.config.hook.pytest_terminal_final_summary(config=self.config,
terminalreporter=self,
exitstatus=exitstatus)
if exitstatus == EXIT_INTERRUPTED:
self._report_keyboardinterrupt()
del self._keyboardinterrupt_memo
Expand Down
15 changes: 15 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,18 @@ def pytest_collect_file(path, parent):
assert not failed
xfailed = [r for r in skipped if hasattr(r, 'wasxfail')]
assert xfailed


def test_summary_list_after_errors(testdir):
"""Ensure the list of errors/fails/xfails/skips appear after tracebacks in terminal reporting."""
testdir.makepyfile("""
import pytest
def test_fail():
assert 0
""")
result = testdir.runpytest('-ra')
result.stdout.fnmatch_lines([
'=* FAILURES *=',
'*= short test summary info =*',
'FAIL test_summary_list_after_errors.py::test_fail',
])

0 comments on commit ede394d

Please sign in to comment.