diff --git a/src/_pytest/_io/terminalwriter.py b/src/_pytest/_io/terminalwriter.py index 4b8219c0d..1b11539db 100644 --- a/src/_pytest/_io/terminalwriter.py +++ b/src/_pytest/_io/terminalwriter.py @@ -225,6 +225,10 @@ class TerminalWriter: ) 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 return "\x1b[0m" + highlighted except pygments.util.ClassNotFound: raise UsageError(