diff --git a/src/_pytest/_io/terminalwriter.py b/src/_pytest/_io/terminalwriter.py index 1b11539db..2b2f49e9a 100644 --- a/src/_pytest/_io/terminalwriter.py +++ b/src/_pytest/_io/terminalwriter.py @@ -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( diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index f810a60dd..fdaa792a3 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -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