From ede394dd2ac7226968e65484da32f13cf1d9e518 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 22 Feb 2018 19:49:30 -0300 Subject: [PATCH] Show "short test summary info" after tracebacks and warnings --- _pytest/hookspec.py | 17 +++++++++++++++-- _pytest/junitxml.py | 2 +- _pytest/pastebin.py | 2 +- _pytest/skipping.py | 2 +- _pytest/terminal.py | 4 ++++ testing/test_skipping.py | 15 +++++++++++++++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index f1b1fe5a28b..0d5ab59187d 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -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) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 98b2d13cf1a..7fd93973e12 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -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)) diff --git a/_pytest/pastebin.py b/_pytest/pastebin.py index b588b021b12..6fdbb607881 100644 --- a/_pytest/pastebin.py +++ b/_pytest/pastebin.py @@ -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 diff --git a/_pytest/skipping.py b/_pytest/skipping.py index 98fc51c7ff8..9cd8e3f6223 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -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": diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 55a632b22f7..2cfcb08b004 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -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 diff --git a/testing/test_skipping.py b/testing/test_skipping.py index db4e6d3f7c9..161a6e69e57 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -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', + ])