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"), 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": if highlighted[-1] == "\n" and source[-1] != "\n":
highlighted = highlighted[:-1] highlighted = highlighted[:-1]
# Some lexers will not set the initial color explicitly # Some lexers will not set the initial color explicitly
# which may lead to the previous color being propagated to the # 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 return "\x1b[0m" + highlighted
except pygments.util.ClassNotFound: except pygments.util.ClassNotFound:
raise UsageError( raise UsageError(

View File

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