fixup! fixup! fixup! fixup! fixup! fixup! Add syntactic highlighting to the error explanations

This commit is contained in:
Benjamin Schubert 2023-12-21 16:29:06 +00:00
parent 5af21936cb
commit 0b87306ec6
2 changed files with 3 additions and 3 deletions

View File

@ -223,12 +223,14 @@ class TerminalWriter:
style=os.getenv("PYTEST_THEME"),
),
)
# pygments terminal formatter may add a newline when there wasn't one.
# We don't want this, remove.
if highlighted[-1] == "\n" and source[-1] != "\n":
highlighted = highlighted[:-1]
# Some lexers will not set the initial color explicitly
# which may lead to the previous color being propagated to the
# start of the expression
# start of the expression, so reset first.
return "\x1b[0m" + highlighted
except pygments.util.ClassNotFound:
raise UsageError(

View File

@ -513,7 +513,6 @@ def _compare_eq_dict(
)
explanation.extend(
highlighter(pprint.pformat({k: left[k] for k in extra_left}))
.strip()
.splitlines()
)
extra_right = set_right - set_left
@ -525,7 +524,6 @@ def _compare_eq_dict(
)
explanation.extend(
highlighter(pprint.pformat({k: right[k] for k in extra_right}))
.strip()
.splitlines()
)
return explanation