Skip to content

Commit 089116b

Browse files
HolyMagician03-UMichnicoddemus
andauthoredApr 10, 2024··
short test summary: do not truncate text when -vv is given
Fix #11777 --------- Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 1f001cd commit 089116b

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed
 

‎AUTHORS

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Endre Galaczi
137137
Eric Hunsberger
138138
Eric Liu
139139
Eric Siegerman
140+
Eric Yuan
140141
Erik Aronesty
141142
Erik Hasse
142143
Erik M. Bray
@@ -432,6 +433,7 @@ Xixi Zhao
432433
Xuan Luong
433434
Xuecong Liao
434435
Yannick Péroux
436+
Yao Xiao
435437
Yoav Caspi
436438
Yuliang Shao
437439
Yusuke Kadowaki

‎changelog/11777.improvement.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Text is no longer truncated in the ``short test summary info`` section when ``-vv`` is given.

‎src/_pytest/terminal.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1408,11 +1408,11 @@ def _get_line_with_reprcrash_message(
14081408
except AttributeError:
14091409
pass
14101410
else:
1411-
if not running_on_ci():
1411+
if running_on_ci() or config.option.verbose >= 2:
1412+
msg = f" - {msg}"
1413+
else:
14121414
available_width = tw.fullwidth - line_width
14131415
msg = _format_trimmed(" - {}", msg, available_width)
1414-
else:
1415-
msg = f" - {msg}"
14161416
if msg is not None:
14171417
line += msg
14181418

‎testing/test_terminal.py

+44-2
Original file line numberDiff line numberDiff line change
@@ -2377,8 +2377,13 @@ def mock_get_pos(*args):
23772377

23782378
monkeypatch.setattr(_pytest.terminal, "_get_node_id_with_markup", mock_get_pos)
23792379

2380+
class Namespace:
2381+
def __init__(self, **kwargs):
2382+
self.__dict__.update(kwargs)
2383+
23802384
class config:
2381-
pass
2385+
def __init__(self):
2386+
self.option = Namespace(verbose=0)
23822387

23832388
class rep:
23842389
def _get_verbose_word(self, *args):
@@ -2399,7 +2404,7 @@ def markup(self, word: str, **markup: str):
23992404
if msg:
24002405
rep.longrepr.reprcrash.message = msg # type: ignore
24012406
actual = _get_line_with_reprcrash_message(
2402-
config, # type: ignore[arg-type]
2407+
config(), # type: ignore[arg-type]
24032408
rep(), # type: ignore[arg-type]
24042409
DummyTerminalWriter(), # type: ignore[arg-type]
24052410
{},
@@ -2443,6 +2448,43 @@ def markup(self, word: str, **markup: str):
24432448
check("🉐🉐🉐🉐🉐\n2nd line", 80, "FAILED nodeid::🉐::withunicode - 🉐🉐🉐🉐🉐")
24442449

24452450

2451+
def test_short_summary_with_verbose(
2452+
monkeypatch: MonkeyPatch, pytester: Pytester
2453+
) -> None:
2454+
"""With -vv do not truncate the summary info (#11777)."""
2455+
# On CI we also do not truncate the summary info, monkeypatch it to ensure we
2456+
# are testing against the -vv flag on CI.
2457+
monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: False)
2458+
2459+
string_length = 200
2460+
pytester.makepyfile(
2461+
f"""
2462+
def test():
2463+
s1 = "A" * {string_length}
2464+
s2 = "B" * {string_length}
2465+
assert s1 == s2
2466+
"""
2467+
)
2468+
2469+
# No -vv, summary info should be truncated.
2470+
result = pytester.runpytest()
2471+
result.stdout.fnmatch_lines(
2472+
[
2473+
"*short test summary info*",
2474+
"* assert 'AAA...",
2475+
],
2476+
)
2477+
2478+
# No truncation with -vv.
2479+
result = pytester.runpytest("-vv")
2480+
result.stdout.fnmatch_lines(
2481+
[
2482+
"*short test summary info*",
2483+
f"*{'A' * string_length}*{'B' * string_length}'",
2484+
]
2485+
)
2486+
2487+
24462488
@pytest.mark.parametrize(
24472489
"seconds, expected",
24482490
[

0 commit comments

Comments
 (0)