Skip to content

Commit 4e405dd

Browse files
committed
Show "short test summary info" after tracebacks and warnings
1 parent da3f404 commit 4e405dd

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

_pytest/hookspec.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,16 @@ def pytest_report_teststatus(report):
489489
Stops at first non-None result, see :ref:`firstresult` """
490490

491491

492-
def pytest_terminal_summary(terminalreporter, exitstatus):
493-
""" add additional section in terminal summary reporting. """
492+
def pytest_terminal_summary(config, terminalreporter, exitstatus):
493+
"""Add a section to terminal summary reporting.
494+
495+
:param _pytest.config.Config config: pytest config object
496+
:param _pytest.terminal.TerminalReporter terminalreporter: the internal terminal reporter object
497+
:param int exitstatus: the exit status that will be reported back to the OS
498+
499+
.. versionadded:: 3.5
500+
The ``config`` parameter.
501+
"""
494502

495503

496504
@hookspec(historic=True)

_pytest/skipping.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
""" support for skip/xfail functions and markers. """
22
from __future__ import absolute_import, division, print_function
33

4-
54
from _pytest.config import hookimpl
65
from _pytest.mark import MarkInfo, MarkDecorator
76
from _pytest.mark.evaluate import MarkEvaluator
@@ -14,11 +13,11 @@ def pytest_addoption(parser):
1413
action="store_true", dest="runxfail", default=False,
1514
help="run tests even if they are marked xfail")
1615

17-
parser.addini("xfail_strict", "default for the strict parameter of xfail "
18-
"markers when not given explicitly (default: "
19-
"False)",
20-
default=False,
21-
type="bool")
16+
parser.addini("xfail_strict",
17+
"default for the strict parameter of xfail "
18+
"markers when not given explicitly (default: False)",
19+
default=False,
20+
type="bool")
2221

2322

2423
def pytest_configure(config):
@@ -130,7 +129,7 @@ def pytest_runtest_makereport(item, call):
130129
rep.outcome = "passed"
131130
rep.wasxfail = rep.longrepr
132131
elif item.config.option.runxfail:
133-
pass # don't interefere
132+
pass # don't interefere
134133
elif call.excinfo and call.excinfo.errisinstance(xfail.Exception):
135134
rep.wasxfail = "reason: " + call.excinfo.value.msg
136135
rep.outcome = "skipped"
@@ -160,6 +159,7 @@ def pytest_runtest_makereport(item, call):
160159
filename, line = item.location[:2]
161160
rep.longrepr = filename, line, reason
162161

162+
163163
# called by terminalreporter progress reporting
164164

165165

@@ -170,6 +170,7 @@ def pytest_report_teststatus(report):
170170
elif report.passed:
171171
return "xpassed", "X", ("XPASS", {'yellow': True})
172172

173+
173174
# called by the terminalreporter instance/plugin
174175

175176

@@ -233,7 +234,7 @@ def folded_skips(skipped):
233234
# TODO: revisit after marks scope would be fixed
234235
when = getattr(event, 'when', None)
235236
if when == 'setup' and 'skip' in keywords and 'pytestmark' not in keywords:
236-
key = (key[0], None, key[2], )
237+
key = (key[0], None, key[2])
237238
d.setdefault(key, []).append(event)
238239
values = []
239240
for key, events in d.items():
@@ -269,6 +270,7 @@ def show_skipped(terminalreporter, lines):
269270
def shower(stat, format):
270271
def show_(terminalreporter, lines):
271272
return show_simple(terminalreporter, lines, stat, format)
273+
272274
return show_
273275

274276

_pytest/terminal.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,21 @@ def pytest_sessionfinish(self, exitstatus):
480480
EXIT_NOTESTSCOLLECTED)
481481
if exitstatus in summary_exit_codes:
482482
self.config.hook.pytest_terminal_summary(terminalreporter=self,
483+
config=self.config,
483484
exitstatus=exitstatus)
484-
self.summary_errors()
485-
self.summary_failures()
486-
self.summary_warnings()
487-
self.summary_passes()
488485
if exitstatus == EXIT_INTERRUPTED:
489486
self._report_keyboardinterrupt()
490487
del self._keyboardinterrupt_memo
491488
self.summary_stats()
492489

490+
@pytest.hookimpl(hookwrapper=True)
491+
def pytest_terminal_summary(self):
492+
self.summary_errors()
493+
self.summary_failures()
494+
yield
495+
self.summary_warnings()
496+
self.summary_passes()
497+
493498
def pytest_keyboard_interrupt(self, excinfo):
494499
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
495500

changelog/3255.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The *short test summary info* section now is displayed after tracebacks and warnings in the terminal.

testing/test_skipping.py

+15
Original file line numberDiff line numberDiff line change
@@ -1065,3 +1065,18 @@ def pytest_collect_file(path, parent):
10651065
assert not failed
10661066
xfailed = [r for r in skipped if hasattr(r, 'wasxfail')]
10671067
assert xfailed
1068+
1069+
1070+
def test_summary_list_after_errors(testdir):
1071+
"""Ensure the list of errors/fails/xfails/skips appear after tracebacks in terminal reporting."""
1072+
testdir.makepyfile("""
1073+
import pytest
1074+
def test_fail():
1075+
assert 0
1076+
""")
1077+
result = testdir.runpytest('-ra')
1078+
result.stdout.fnmatch_lines([
1079+
'=* FAILURES *=',
1080+
'*= short test summary info =*',
1081+
'FAIL test_summary_list_after_errors.py::test_fail',
1082+
])

0 commit comments

Comments
 (0)