Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/10264.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the :option:`--no-truncate-summary` option to show complete first lines of messages in the short test summary.
5 changes: 5 additions & 0 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,11 @@ Output and Reporting

Force condensed summary output regardless of verbosity level.

.. option:: --no-truncate-summary

Do not truncate messages in the short test summary, regardless of terminal width.
Only the first line of each message is displayed.

.. option:: -l, --showlocals

Show locals in tracebacks (disabled by default).
Expand Down
15 changes: 12 additions & 3 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def pytest_addoption(parser: Parser) -> None:
default=False,
help="Force condensed summary output regardless of verbosity level.",
)
group.addoption(
"--no-truncate-summary",
action="store_true",
default=False,
help="Do not truncate messages in the short test summary.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new flag's help says not to truncate the summary, but --force-short-summary still takes precedence when both are passed. the tests make that behavior clear, so could the help text mention the exception? otherwise the two flags together are a little surprising.

)
group._addoption( # private to use reserved lower-case short option
"-q",
"--quiet",
Expand Down Expand Up @@ -1596,9 +1602,12 @@ def _get_line_with_reprcrash_message(
except AttributeError:
pass
else:
if (
running_on_ci() or config.option.verbose >= 2
) and not config.option.force_short_summary:
if config.option.force_short_summary:
available_width = tw.fullwidth - line_width
msg = _format_trimmed(" - {}", msg, available_width)
elif config.option.no_truncate_summary:
msg = " - " + msg.partition("\n")[0]
elif running_on_ci() or config.option.verbose >= 2:
msg = f" - {msg}"
else:
available_width = tw.fullwidth - line_width
Expand Down
54 changes: 53 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2738,7 +2738,11 @@ def __init__(self, **kwargs):

class config:
def __init__(self):
self.option = Namespace(verbose=0)
self.option = Namespace(
verbose=0,
force_short_summary=False,
no_truncate_summary=False,
)

class rep:
def _get_verbose_word_with_markup(self, *args):
Expand Down Expand Up @@ -2886,6 +2890,54 @@ def test():
)


@pytest.mark.parametrize(
("args", "running_on_ci", "truncated"),
[
([], False, True),
(["--no-truncate-summary"], False, False),
(["--no-truncate-summary"], True, False),
(["-vv", "--force-short-summary"], False, True),
(["--no-truncate-summary", "-vv", "--force-short-summary"], False, True),
],
)
def test_no_truncate_summary(
monkeypatch: MonkeyPatch,
pytester: Pytester,
args: list[str],
running_on_ci: bool,
truncated: bool,
) -> None:
monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: running_on_ci)
monkeypatch.setenv("COLUMNS", "80")
pytester.makepyfile(
test_summary="""
import pytest

def test_fail():
pytest.fail("A" * 100 + "\\nSECOND_LINE")
"""
)

result = pytester.runpytest(*args)
assert result.ret == 1

summary_index = next(
i
for i, line in enumerate(result.stdout.lines)
if "short test summary info" in line
)
summary_line = next(
line
for line in result.stdout.lines[summary_index + 1 :]
if line.startswith("FAILED test_summary.py::test_fail ")
)
assert "SECOND_LINE" not in summary_line
if truncated:
assert summary_line.endswith("...")
else:
assert "A" * 100 in summary_line


@pytest.mark.parametrize(
"seconds, expected",
[
Expand Down
Loading