diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index 22acafbdd..9abed5b1f 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -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): diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 408fa076e..295dd832c 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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.""" diff --git a/testing/test_skipping.py b/testing/test_skipping.py index e5206a44e..fb0cf60e0 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -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", ] ) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index d0fdce23e..9b221366f 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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):