Skip to content

Commit d5c020d

Browse files
committed
always show full diff in ci
follow-up to #1314, for similar reasons closes #9023
1 parent 2367e6e commit d5c020d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

changelog/9023.feature.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Full diffs are now always shown for equality assertions of iterables when
3+
`CI` or ``BUILD_NUMBER`` is found in the environment, even when ``-v`` isn't
4+
used.

src/_pytest/assertion/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def _surrounding_parens_on_own_lines(lines: List[str]) -> None:
287287
def _compare_eq_iterable(
288288
left: Iterable[Any], right: Iterable[Any], verbose: int = 0
289289
) -> List[str]:
290-
if not verbose:
290+
if not verbose and not running_on_ci():
291291
return ["Use -v to get the full diff"]
292292
# dynamic import to speedup pytest
293293
import difflib

testing/test_assertion.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from _pytest import outcomes
1414
from _pytest.assertion import truncate
1515
from _pytest.assertion import util
16+
from _pytest.monkeypatch import MonkeyPatch
1617
from _pytest.pytester import Pytester
1718

1819

@@ -448,6 +449,25 @@ def test_iterable_full_diff(self, left, right, expected) -> None:
448449
assert verbose_expl is not None
449450
assert "\n".join(verbose_expl).endswith(textwrap.dedent(expected).strip())
450451

452+
def test_iterable_full_diff_ci(
453+
self, monkeypatch: MonkeyPatch, pytester: Pytester
454+
) -> None:
455+
pytester.makepyfile(
456+
r"""
457+
def test_full_diff():
458+
left = [0, 1]
459+
right = [0, 2]
460+
assert left == right
461+
"""
462+
)
463+
monkeypatch.setenv("CI", "true")
464+
result = pytester.runpytest()
465+
result.stdout.fnmatch_lines(["E Full diff:"])
466+
467+
monkeypatch.delenv("CI", raising=False)
468+
result = pytester.runpytest()
469+
result.stdout.fnmatch_lines(["E Use -v to get the full diff"])
470+
451471
def test_list_different_lengths(self) -> None:
452472
expl = callequal([0, 1], [0, 1, 2])
453473
assert expl is not None

0 commit comments

Comments
 (0)