diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 7a6613bfd..cc8967ed3 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -338,8 +338,8 @@ def _compare_eq_iterable( lines_right = len(right_formatting) if lines_left > 1 or lines_right > 1: - _surrounding_parens_on_own_lines(left_formatting) - _surrounding_parens_on_own_lines(right_formatting) + _surrounding_parens_on_own_lines(left_formatting) + _surrounding_parens_on_own_lines(right_formatting) else: left_formatting = PrettyPrinter().pformat(left).splitlines() right_formatting = PrettyPrinter().pformat(right).splitlines() @@ -359,6 +359,18 @@ def _compare_eq_iterable( return explanation +def _surrounding_parens_on_own_lines(lines: List[str]) -> None: + """Move opening/closing parenthesis/bracket to own lines.""" + opening = lines[0][:1] + if opening in ["(", "[", "{"]: + lines[0] = " " + lines[0][1:] + lines[:] = [opening] + lines + closing = lines[-1][-1:] + if closing in [")", "]", "}"]: + lines[-1] = lines[-1][:-1] + "," + lines[:] = lines + [closing] + + def _is_empty_vs_non_empty(left: Iterable[Any], right: Iterable[Any]) -> bool: is_left_empty = not any(left) if isinstance(left, Iterable) else not left is_right_empty = not any(right) if isinstance(right, Iterable) else not right diff --git a/testing/test_assertion.py b/testing/test_assertion.py index f3e8ae249..d7fd51a1e 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -416,14 +416,17 @@ class TestAssert_reprcompare: assert callequal(m1, []) == [ "['This is som...e full diff.'] == []", + "", "Left contains one more item: 'This is some dummy test which shows the " "strange way in which Pycharm displays the full diff.'", "Use -v to get more diff", ] assert callequal(m1, [], verbose=True) == [ "['This is som...e full diff.'] == []", + "", "Left contains one more item: 'This is some dummy test which shows the " "strange way in which Pycharm displays the full diff.'", + "", "Full diff:", "- []", "+ ['This is some dummy test which shows the strange way in which Pycharm " @@ -432,6 +435,7 @@ class TestAssert_reprcompare: assert callequal(m2, []) == [ "['This is som...e full diff.'] == []", + "", "Left contains one more item: 'This is some dummy test which shows the " "strange way in which Pycharm displays the full diff.This is some dummy test " "which shows the strange way in which Pycharm displays the full diff.'", @@ -440,9 +444,11 @@ class TestAssert_reprcompare: assert callequal(m2, [], verbose=True) == [ "['This is som...e full diff.'] == []", + "", "Left contains one more item: 'This is some dummy test which shows the " "strange way in which Pycharm displays the full diff.This is some dummy test " "which shows the strange way in which Pycharm displays the full diff.'", + "" "", "Full diff:", "- []", "+ ['This is some dummy test which shows the strange way in which Pycharm " @@ -452,15 +458,18 @@ class TestAssert_reprcompare: assert callequal(m3, []) == [ "['This is som...e full diff.'] == []", + "", "Left contains 2 more items, first extra item: 'This is some dummy test which shows the strange way in " "which Pycharm displays the full diff.'", - "Use -v to get more diff", + "" "Use -v to get more diff", ] assert callequal(m3, [], verbose=True) == [ "['This is som...e full diff.'] == []", + "", "Left contains 2 more items, first extra item: 'This is some dummy test which shows the strange way in " "which Pycharm displays the full diff.'", + "", "Full diff:", " [", "- ,",