Skip to content

Commit

Permalink
Do not truncate crash messages in short test summary on CI (#9933)
Browse files Browse the repository at this point in the history
Closes #9920
  • Loading branch information
sommersoft committed May 13, 2022
1 parent 69fb79e commit 56c2666
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/9920.improvement.rst
@@ -0,0 +1 @@
Display full crash messages in ``short test summary info``, when runng in a CI environment.
8 changes: 6 additions & 2 deletions src/_pytest/terminal.py
Expand Up @@ -37,6 +37,7 @@
from _pytest._code.code import ExceptionRepr
from _pytest._io import TerminalWriter
from _pytest._io.wcwidth import wcswidth
from _pytest.assertion.util import running_on_ci
from _pytest.compat import final
from _pytest.config import _PluggyPlugin
from _pytest.config import Config
Expand Down Expand Up @@ -1315,8 +1316,11 @@ def _get_line_with_reprcrash_message(
except AttributeError:
pass
else:
available_width = tw.fullwidth - line_width
msg = _format_trimmed(" - {}", msg, available_width)
if not running_on_ci():
available_width = tw.fullwidth - line_width
msg = _format_trimmed(" - {}", msg, available_width)
else:
msg = f" - {msg}"
if msg is not None:
line += msg

Expand Down
18 changes: 16 additions & 2 deletions testing/test_terminal.py
Expand Up @@ -1139,7 +1139,21 @@ def test():
assert result.stdout.lines.count(expected) == 1


def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None:
@pytest.mark.parametrize(
("use_ci", "expected_message"),
(
(True, f"- AssertionError: {'this_failed'*100}"),
(False, "- AssertionError: this_failedt..."),
),
ids=("on CI", "not on CI"),
)
def test_fail_extra_reporting(
pytester: Pytester, monkeypatch, use_ci: bool, expected_message: str
) -> None:
if use_ci:
monkeypatch.setenv("CI", "true")
else:
monkeypatch.delenv("CI", raising=False)
monkeypatch.setenv("COLUMNS", "80")
pytester.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
result = pytester.runpytest("-rN")
Expand All @@ -1148,7 +1162,7 @@ def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None:
result.stdout.fnmatch_lines(
[
"*test summary*",
"FAILED test_fail_extra_reporting.py::test_this - AssertionError: this_failedt...",
f"FAILED test_fail_extra_reporting.py::test_this {expected_message}",
]
)

Expand Down

0 comments on commit 56c2666

Please sign in to comment.