From d5c020d8c5958e14fb401f4e4c706ccc612d41af Mon Sep 17 00:00:00 2001 From: David Szotten Date: Thu, 19 Aug 2021 16:27:07 +0000 Subject: [PATCH] always show full diff in ci follow-up to #1314, for similar reasons closes #9023 --- changelog/9023.feature.rst | 4 ++++ src/_pytest/assertion/util.py | 2 +- testing/test_assertion.py | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 changelog/9023.feature.rst diff --git a/changelog/9023.feature.rst b/changelog/9023.feature.rst new file mode 100644 index 00000000000..86a819a84e0 --- /dev/null +++ b/changelog/9023.feature.rst @@ -0,0 +1,4 @@ + +Full diffs are now always shown for equality assertions of iterables when +`CI` or ``BUILD_NUMBER`` is found in the environment, even when ``-v`` isn't +used. diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 493ab91425c..19f1089c20a 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -287,7 +287,7 @@ def _surrounding_parens_on_own_lines(lines: List[str]) -> None: def _compare_eq_iterable( left: Iterable[Any], right: Iterable[Any], verbose: int = 0 ) -> List[str]: - if not verbose: + if not verbose and not running_on_ci(): return ["Use -v to get the full diff"] # dynamic import to speedup pytest import difflib diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 289fe5b083f..e8717590d53 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -13,6 +13,7 @@ from _pytest import outcomes from _pytest.assertion import truncate from _pytest.assertion import util +from _pytest.monkeypatch import MonkeyPatch from _pytest.pytester import Pytester @@ -448,6 +449,25 @@ def test_iterable_full_diff(self, left, right, expected) -> None: assert verbose_expl is not None assert "\n".join(verbose_expl).endswith(textwrap.dedent(expected).strip()) + def test_iterable_full_diff_ci( + self, monkeypatch: MonkeyPatch, pytester: Pytester + ) -> None: + pytester.makepyfile( + r""" + def test_full_diff(): + left = [0, 1] + right = [0, 2] + assert left == right + """ + ) + monkeypatch.setenv("CI", "true") + result = pytester.runpytest() + result.stdout.fnmatch_lines(["E Full diff:"]) + + monkeypatch.delenv("CI", raising=False) + result = pytester.runpytest() + result.stdout.fnmatch_lines(["E Use -v to get the full diff"]) + def test_list_different_lengths(self) -> None: expl = callequal([0, 1], [0, 1, 2]) assert expl is not None