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 argparse
import datetime import datetime
import inspect import inspect
import os
import platform import platform
import sys import sys
import warnings import warnings
@ -1295,8 +1296,11 @@ def _get_line_with_reprcrash_message(
except AttributeError: except AttributeError:
pass pass
else: else:
available_width = termwidth - line_width if not os.environ.get("CI", False):
msg = _format_trimmed(" - {}", msg, available_width) available_width = termwidth - line_width
msg = _format_trimmed(" - {}", msg, available_width)
else:
msg = f" - {msg}"
if msg is not None: if msg is not None:
line += msg line += msg

View File

@ -1139,7 +1139,19 @@ class TestTerminalFunctional:
assert result.stdout.lines.count(expected) == 1 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") monkeypatch.setenv("COLUMNS", "80")
pytester.makepyfile("def test_this(): assert 0, 'this_failed' * 100") pytester.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
result = pytester.runpytest("-rN") result = pytester.runpytest("-rN")
@ -1148,7 +1160,7 @@ def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None:
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"*test summary*", "*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]}",
] ]
) )