Skip to content

Commit

Permalink
_get_line_with_reprcrash_message: remove duplicate prefix (#7)
Browse files Browse the repository at this point in the history
Before:

> FAILED foo/test.py::test_bar - Failed: Database access not allowed, …

After:

> FAILED foo/test.py::test_bar - Database access not allowed, …
  • Loading branch information
blueyed committed Oct 22, 2019
1 parent a544868 commit 6b2ada0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/_pytest/terminal.py
Expand Up @@ -14,6 +14,7 @@
import pluggy
import py
from more_itertools import collapse
from wcwidth import wcswidth

import pytest
from _pytest import nodes
Expand Down Expand Up @@ -990,8 +991,6 @@ def _get_pos(config, rep):

def _get_line_with_reprcrash_message(config, rep, termwidth):
"""Get summary line for a report, trying to add reprcrash message."""
from wcwidth import wcswidth

verbose_word = rep._get_verbose_word(config)
pos = _get_pos(config, rep)

Expand All @@ -1011,8 +1010,13 @@ def _get_line_with_reprcrash_message(config, rep, termwidth):
i = msg.find("\n")
if i != -1:
msg = msg[:i]
len_msg = wcswidth(msg)

# Remove duplicate prefix, e.g. "Failed:" from pytest.fail.
implicit_prefix = verbose_word.lower() + ":"
if msg[: len(implicit_prefix)].lower() == implicit_prefix:
msg = msg[len(implicit_prefix) + 1 :]

len_msg = wcswidth(msg)
sep, len_sep = " - ", 3
max_len_msg = termwidth - len_line - len_sep
if max_len_msg >= len_ellipsis:
Expand Down
4 changes: 4 additions & 0 deletions testing/test_skipping.py
Expand Up @@ -1144,6 +1144,9 @@ def test_summary_list_after_errors(testdir):
import pytest
def test_fail():
assert 0
def test_pytest_fail():
pytest.fail("fail exc")
"""
)
result = testdir.runpytest("-ra")
Expand All @@ -1152,6 +1155,7 @@ def test_fail():
"=* FAILURES *=",
"*= short test summary info =*",
"FAILED test_summary_list_after_errors.py::test_fail - assert 0",
"FAILED test_summary_list_after_errors.py::test_pytest_fail - fail exc",
]
)

Expand Down

0 comments on commit 6b2ada0

Please sign in to comment.