Separate the various parts of the error report with newlines (#11659)

Previously the error report would have all sections glued together:

- The assertion representation
- The error explanation
- The full diff

This makes it hard to see at a glance where which one starts and ends.

One of the representation (dataclasses, tuples, attrs) does display a
newlines at the start already.

Let's add a newlines before the error explanation and before the full
diff, so we get an easier to read report.

This has one disadvantage: we get one line less in the least verbose
mode, where the output gets truncated.
This commit is contained in:
Benjamin Schubert
2023-12-06 09:25:00 +00:00
committed by GitHub
parent cd269f0e6d
commit a536f49d91
4 changed files with 74 additions and 23 deletions

View File

@@ -230,6 +230,8 @@ def assertrepr_compare(
if not explanation:
return None
if explanation[0] != "":
explanation = [""] + explanation
return [summary] + explanation
@@ -332,7 +334,7 @@ def _compare_eq_iterable(
left_formatting = PrettyPrinter().pformat(left).splitlines()
right_formatting = PrettyPrinter().pformat(right).splitlines()
explanation = ["Full diff:"]
explanation = ["", "Full diff:"]
# "right" is the expected base against which we compare "left",
# see https://github.com/pytest-dev/pytest/issues/3333
explanation.extend(