Skip to content

Commit 56c2666

Browse files
authored
Do not truncate crash messages in short test summary on CI (#9933)
Closes #9920
1 parent 69fb79e commit 56c2666

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

changelog/9920.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display full crash messages in ``short test summary info``, when runng in a CI environment.

src/_pytest/terminal.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from _pytest._code.code import ExceptionRepr
3838
from _pytest._io import TerminalWriter
3939
from _pytest._io.wcwidth import wcswidth
40+
from _pytest.assertion.util import running_on_ci
4041
from _pytest.compat import final
4142
from _pytest.config import _PluggyPlugin
4243
from _pytest.config import Config
@@ -1315,8 +1316,11 @@ def _get_line_with_reprcrash_message(
13151316
except AttributeError:
13161317
pass
13171318
else:
1318-
available_width = tw.fullwidth - line_width
1319-
msg = _format_trimmed(" - {}", msg, available_width)
1319+
if not running_on_ci():
1320+
available_width = tw.fullwidth - line_width
1321+
msg = _format_trimmed(" - {}", msg, available_width)
1322+
else:
1323+
msg = f" - {msg}"
13201324
if msg is not None:
13211325
line += msg
13221326

testing/test_terminal.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,21 @@ def test():
11391139
assert result.stdout.lines.count(expected) == 1
11401140

11411141

1142-
def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None:
1142+
@pytest.mark.parametrize(
1143+
("use_ci", "expected_message"),
1144+
(
1145+
(True, f"- AssertionError: {'this_failed'*100}"),
1146+
(False, "- AssertionError: this_failedt..."),
1147+
),
1148+
ids=("on CI", "not on CI"),
1149+
)
1150+
def test_fail_extra_reporting(
1151+
pytester: Pytester, monkeypatch, use_ci: bool, expected_message: str
1152+
) -> None:
1153+
if use_ci:
1154+
monkeypatch.setenv("CI", "true")
1155+
else:
1156+
monkeypatch.delenv("CI", raising=False)
11431157
monkeypatch.setenv("COLUMNS", "80")
11441158
pytester.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
11451159
result = pytester.runpytest("-rN")
@@ -1148,7 +1162,7 @@ def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None:
11481162
result.stdout.fnmatch_lines(
11491163
[
11501164
"*test summary*",
1151-
"FAILED test_fail_extra_reporting.py::test_this - AssertionError: this_failedt...",
1165+
f"FAILED test_fail_extra_reporting.py::test_this {expected_message}",
11521166
]
11531167
)
11541168

0 commit comments

Comments
 (0)