Refactor into TerminalReporter.short_test_summary
This commit is contained in:
parent
c70ecd49ca
commit
06029d11d3
|
@ -678,6 +678,7 @@ class TerminalReporter(object):
|
||||||
self.summary_failures()
|
self.summary_failures()
|
||||||
self.summary_warnings()
|
self.summary_warnings()
|
||||||
yield
|
yield
|
||||||
|
self.short_test_summary()
|
||||||
self.summary_passes()
|
self.summary_passes()
|
||||||
# Display any extra warnings from teardown here (if any).
|
# Display any extra warnings from teardown here (if any).
|
||||||
self.summary_warnings()
|
self.summary_warnings()
|
||||||
|
@ -873,37 +874,23 @@ class TerminalReporter(object):
|
||||||
if self.verbosity == -1:
|
if self.verbosity == -1:
|
||||||
self.write_line(msg, **markup)
|
self.write_line(msg, **markup)
|
||||||
|
|
||||||
|
def short_test_summary(self):
|
||||||
def pytest_terminal_summary(terminalreporter):
|
if not self.reportchars:
|
||||||
tr = terminalreporter
|
|
||||||
if not tr.reportchars:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
lines = []
|
def show_simple(lines, stat):
|
||||||
for char in tr.reportchars:
|
failed = self.stats.get(stat)
|
||||||
action = REPORTCHAR_ACTIONS.get(char, lambda tr, lines: None)
|
|
||||||
action(terminalreporter, lines)
|
|
||||||
|
|
||||||
if lines:
|
|
||||||
tr._tw.sep("=", "short test summary info")
|
|
||||||
for line in lines:
|
|
||||||
tr._tw.line(line)
|
|
||||||
|
|
||||||
|
|
||||||
def show_simple(terminalreporter, lines, stat):
|
|
||||||
failed = terminalreporter.stats.get(stat)
|
|
||||||
if failed:
|
if failed:
|
||||||
config = terminalreporter.config
|
config = self.config
|
||||||
for rep in failed:
|
for rep in failed:
|
||||||
verbose_word = _get_report_str(config, rep)
|
verbose_word = _get_report_str(config, rep)
|
||||||
pos = _get_pos(config, rep)
|
pos = _get_pos(config, rep)
|
||||||
lines.append("%s %s" % (verbose_word, pos))
|
lines.append("%s %s" % (verbose_word, pos))
|
||||||
|
|
||||||
|
def show_xfailed(lines):
|
||||||
def show_xfailed(terminalreporter, lines):
|
xfailed = self.stats.get("xfailed")
|
||||||
xfailed = terminalreporter.stats.get("xfailed")
|
|
||||||
if xfailed:
|
if xfailed:
|
||||||
config = terminalreporter.config
|
config = self.config
|
||||||
for rep in xfailed:
|
for rep in xfailed:
|
||||||
verbose_word = _get_report_str(config, rep)
|
verbose_word = _get_report_str(config, rep)
|
||||||
pos = _get_pos(config, rep)
|
pos = _get_pos(config, rep)
|
||||||
|
@ -912,19 +899,75 @@ def show_xfailed(terminalreporter, lines):
|
||||||
if reason:
|
if reason:
|
||||||
lines.append(" " + str(reason))
|
lines.append(" " + str(reason))
|
||||||
|
|
||||||
|
def show_xpassed(lines):
|
||||||
def show_xpassed(terminalreporter, lines):
|
xpassed = self.stats.get("xpassed")
|
||||||
xpassed = terminalreporter.stats.get("xpassed")
|
|
||||||
if xpassed:
|
if xpassed:
|
||||||
config = terminalreporter.config
|
config = self.config
|
||||||
for rep in xpassed:
|
for rep in xpassed:
|
||||||
verbose_word = _get_report_str(config, rep)
|
verbose_word = _get_report_str(config, rep)
|
||||||
pos = _get_pos(config, rep)
|
pos = _get_pos(config, rep)
|
||||||
reason = rep.wasxfail
|
reason = rep.wasxfail
|
||||||
lines.append("%s %s %s" % (verbose_word, pos, reason))
|
lines.append("%s %s %s" % (verbose_word, pos, reason))
|
||||||
|
|
||||||
|
def show_skipped(lines):
|
||||||
|
skipped = self.stats.get("skipped", [])
|
||||||
|
if skipped:
|
||||||
|
fskips = _folded_skips(skipped)
|
||||||
|
if fskips:
|
||||||
|
verbose_word = _get_report_str(self.config, report=skipped[0])
|
||||||
|
for num, fspath, lineno, reason in fskips:
|
||||||
|
if reason.startswith("Skipped: "):
|
||||||
|
reason = reason[9:]
|
||||||
|
if lineno is not None:
|
||||||
|
lines.append(
|
||||||
|
"%s [%d] %s:%d: %s"
|
||||||
|
% (verbose_word, num, fspath, lineno + 1, reason)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
lines.append(
|
||||||
|
"%s [%d] %s: %s" % (verbose_word, num, fspath, reason)
|
||||||
|
)
|
||||||
|
|
||||||
def folded_skips(skipped):
|
def shower(stat):
|
||||||
|
def show_(lines):
|
||||||
|
return show_simple(lines, stat)
|
||||||
|
|
||||||
|
return show_
|
||||||
|
|
||||||
|
def _get_report_str(config, report):
|
||||||
|
_category, _short, verbose = config.hook.pytest_report_teststatus(
|
||||||
|
report=report, config=config
|
||||||
|
)
|
||||||
|
return verbose
|
||||||
|
|
||||||
|
def _get_pos(config, rep):
|
||||||
|
nodeid = config.cwd_relative_nodeid(rep.nodeid)
|
||||||
|
return nodeid
|
||||||
|
|
||||||
|
REPORTCHAR_ACTIONS = {
|
||||||
|
"x": show_xfailed,
|
||||||
|
"X": show_xpassed,
|
||||||
|
"f": shower("failed"),
|
||||||
|
"F": shower("failed"),
|
||||||
|
"s": show_skipped,
|
||||||
|
"S": show_skipped,
|
||||||
|
"p": shower("passed"),
|
||||||
|
"E": shower("error"),
|
||||||
|
}
|
||||||
|
|
||||||
|
lines = []
|
||||||
|
for char in self.reportchars:
|
||||||
|
action = REPORTCHAR_ACTIONS.get(char)
|
||||||
|
if action: # skipping e.g. "P" (passed with output) here.
|
||||||
|
action(lines)
|
||||||
|
|
||||||
|
if lines:
|
||||||
|
self.write_sep("=", "short test summary info")
|
||||||
|
for line in lines:
|
||||||
|
self.write_line(line)
|
||||||
|
|
||||||
|
|
||||||
|
def _folded_skips(skipped):
|
||||||
d = {}
|
d = {}
|
||||||
for event in skipped:
|
for event in skipped:
|
||||||
key = event.longrepr
|
key = event.longrepr
|
||||||
|
@ -946,56 +989,6 @@ def folded_skips(skipped):
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
def show_skipped(terminalreporter, lines):
|
|
||||||
tr = terminalreporter
|
|
||||||
skipped = tr.stats.get("skipped", [])
|
|
||||||
if skipped:
|
|
||||||
fskips = folded_skips(skipped)
|
|
||||||
if fskips:
|
|
||||||
verbose_word = _get_report_str(terminalreporter.config, report=skipped[0])
|
|
||||||
for num, fspath, lineno, reason in fskips:
|
|
||||||
if reason.startswith("Skipped: "):
|
|
||||||
reason = reason[9:]
|
|
||||||
if lineno is not None:
|
|
||||||
lines.append(
|
|
||||||
"%s [%d] %s:%d: %s"
|
|
||||||
% (verbose_word, num, fspath, lineno + 1, reason)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason))
|
|
||||||
|
|
||||||
|
|
||||||
def shower(stat):
|
|
||||||
def show_(terminalreporter, lines):
|
|
||||||
return show_simple(terminalreporter, lines, stat)
|
|
||||||
|
|
||||||
return show_
|
|
||||||
|
|
||||||
|
|
||||||
def _get_report_str(config, report):
|
|
||||||
_category, _short, verbose = config.hook.pytest_report_teststatus(
|
|
||||||
report=report, config=config
|
|
||||||
)
|
|
||||||
return verbose
|
|
||||||
|
|
||||||
|
|
||||||
def _get_pos(config, rep):
|
|
||||||
nodeid = config.cwd_relative_nodeid(rep.nodeid)
|
|
||||||
return nodeid
|
|
||||||
|
|
||||||
|
|
||||||
REPORTCHAR_ACTIONS = {
|
|
||||||
"x": show_xfailed,
|
|
||||||
"X": show_xpassed,
|
|
||||||
"f": shower("failed"),
|
|
||||||
"F": shower("failed"),
|
|
||||||
"s": show_skipped,
|
|
||||||
"S": show_skipped,
|
|
||||||
"p": shower("passed"),
|
|
||||||
"E": shower("error"),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def build_summary_stats_line(stats):
|
def build_summary_stats_line(stats):
|
||||||
known_types = (
|
known_types = (
|
||||||
"failed passed skipped deselected xfailed xpassed warnings error".split()
|
"failed passed skipped deselected xfailed xpassed warnings error".split()
|
||||||
|
|
|
@ -16,9 +16,9 @@ import py
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||||
from _pytest.reports import BaseReport
|
from _pytest.reports import BaseReport
|
||||||
|
from _pytest.terminal import _folded_skips
|
||||||
from _pytest.terminal import _plugin_nameversions
|
from _pytest.terminal import _plugin_nameversions
|
||||||
from _pytest.terminal import build_summary_stats_line
|
from _pytest.terminal import build_summary_stats_line
|
||||||
from _pytest.terminal import folded_skips
|
|
||||||
from _pytest.terminal import getreportopt
|
from _pytest.terminal import getreportopt
|
||||||
from _pytest.terminal import TerminalReporter
|
from _pytest.terminal import TerminalReporter
|
||||||
|
|
||||||
|
@ -1552,7 +1552,7 @@ def test_skip_reasons_folding():
|
||||||
ev3.longrepr = longrepr
|
ev3.longrepr = longrepr
|
||||||
ev3.skipped = True
|
ev3.skipped = True
|
||||||
|
|
||||||
values = folded_skips([ev1, ev2, ev3])
|
values = _folded_skips([ev1, ev2, ev3])
|
||||||
assert len(values) == 1
|
assert len(values) == 1
|
||||||
num, fspath, lineno, reason = values[0]
|
num, fspath, lineno, reason = values[0]
|
||||||
assert num == 3
|
assert num == 3
|
||||||
|
|
Loading…
Reference in New Issue