From 56c266640ef4ee60659f81af36bc95f6e6ca9cfa Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 13 May 2022 06:15:52 -0500 Subject: [PATCH] Do not truncate crash messages in short test summary on CI (#9933) Closes #9920 --- changelog/9920.improvement.rst | 1 + src/_pytest/terminal.py | 8 ++++++-- testing/test_terminal.py | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 changelog/9920.improvement.rst diff --git a/changelog/9920.improvement.rst b/changelog/9920.improvement.rst new file mode 100644 index 00000000000..ed47e872cac --- /dev/null +++ b/changelog/9920.improvement.rst @@ -0,0 +1 @@ +Display full crash messages in ``short test summary info``, when runng in a CI environment. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 41a9861a3ce..bb07b3ce7c6 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -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 @@ -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 diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 5b464d68bfb..9a8dd4d9ac9 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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") @@ -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}", ] )