Display message from reprcrash in short test summary

This is useful to see common patterns easily, but also for single
failures already.
This commit is contained in:
Daniel Hahler 2019-03-29 17:59:02 +01:00
parent e04936fc29
commit 3d0ecd03ed
4 changed files with 32 additions and 6 deletions

View File

@ -211,7 +211,25 @@ def show_simple(terminalreporter, lines, stat):
for rep in failed:
verbose_word = _get_report_str(config, rep)
pos = _get_pos(config, rep)
lines.append("%s %s" % (verbose_word, pos))
line = "%s %s" % (verbose_word, pos)
try:
msg = rep.longrepr.reprcrash.message
except AttributeError:
pass
else:
# Only use the first line.
# Might be worth having a short_message property, which
# could default to this behavior.
i = msg.find("\n")
if i != -1:
msg = msg[:i]
max_len = terminalreporter.writer.fullwidth - len(line) - 2
if len(msg) > max_len:
msg = msg[: (max_len - 1)] + ""
line += ": %s" % msg
lines.append(line)
def show_xfailed(terminalreporter, lines):

View File

@ -865,7 +865,9 @@ class TestInvocationVariants(object):
_fail, _sep, testid = line.partition(" ")
break
result = testdir.runpytest(testid, "-rf")
result.stdout.fnmatch_lines([line, "*1 failed*"])
result.stdout.fnmatch_lines(
["FAILED test_doctest_id.txt::test_doctest_id.txt", "*1 failed*"]
)
def test_core_backward_compatibility(self):
"""Test backward compatibility for get_plugin_manager function. See #787."""

View File

@ -1208,6 +1208,6 @@ def test_summary_list_after_errors(testdir):
[
"=* FAILURES *=",
"*= short test summary info =*",
"FAILED test_summary_list_after_errors.py::test_fail",
"FAILED test_summary_list_after_errors.py::test_fail: assert 0",
]
)

View File

@ -726,12 +726,18 @@ class TestTerminalFunctional(object):
result.stdout.fnmatch_lines(["collected 3 items", "hello from hook: 3 items"])
def test_fail_extra_reporting(testdir):
testdir.makepyfile("def test_this(): assert 0")
def test_fail_extra_reporting(testdir, monkeypatch):
monkeypatch.setenv("COLUMNS", "80")
testdir.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
result = testdir.runpytest()
assert "short test summary" not in result.stdout.str()
result = testdir.runpytest("-rf")
result.stdout.fnmatch_lines(["*test summary*", "FAIL*test_fail_extra_reporting*"])
result.stdout.fnmatch_lines(
[
"*test summary*",
"FAILED test_fail_extra_reporting.py::test_this: AssertionError: this_failedthis…",
]
)
def test_fail_reporting_on_pass(testdir):