skip `_format_trimmed` and do not truncate crashes if on CI

This commit is contained in:
sommersoft 2022-05-09 07:42:00 -05:00
parent 5f9d68c8d9
commit 7ac00741f2
3 changed files with 21 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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]}",
]
)