diff --git a/changelog/9920.improvement.rst b/changelog/9920.improvement.rst new file mode 100644 index 000000000..39c2bcd7f --- /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. CI environment is detected based on the presence of a ``CI`` environment variable. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index b4848c48a..1f20b05c1 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -5,6 +5,7 @@ This is a good source for looking at the various reporting hooks. import argparse import datetime import inspect +import os import platform import sys import warnings @@ -1295,8 +1296,11 @@ def _get_line_with_reprcrash_message( except AttributeError: pass else: - available_width = termwidth - line_width - msg = _format_trimmed(" - {}", msg, available_width) + if not os.environ.get("CI", False): + available_width = termwidth - 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 f0e58e5b4..2f1facbe1 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1139,7 +1139,19 @@ class TestTerminalFunctional: assert result.stdout.lines.count(expected) == 1 -def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None: +@pytest.mark.parametrize( + "use_CI", + ( + (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) -> None: + if use_CI[0]: + 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 +1160,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 {use_CI[1]}", ] )