Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do Not Truncate Crash Messages In Short Test Summary on CI #9933

Merged
merged 6 commits into from May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions 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.
sommersoft marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 6 additions & 2 deletions src/_pytest/terminal.py
Expand Up @@ -5,6 +5,7 @@
import argparse
import datetime
import inspect
import os
import platform
import sys
import warnings
Expand Down Expand Up @@ -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):
sommersoft marked this conversation as resolved.
Show resolved Hide resolved
available_width = termwidth - line_width
msg = _format_trimmed(" - {}", msg, available_width)
else:
msg = f" - {msg}"
if msg is not None:
line += msg

Expand Down
16 changes: 14 additions & 2 deletions testing/test_terminal.py
Expand Up @@ -1139,7 +1139,19 @@ def test():
assert result.stdout.lines.count(expected) == 1


def test_fail_extra_reporting(pytester: Pytester, monkeypatch) -> None:
@pytest.mark.parametrize(
"use_CI",
sommersoft marked this conversation as resolved.
Show resolved Hide resolved
(
(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")
Expand All @@ -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]}",
]
)

Expand Down