From e16a67af873462e3f5d3023ab100222cc0c1e29b Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Wed, 20 Dec 2023 11:54:55 +0000 Subject: [PATCH] fixup! Put a 'reset' color in front of the highlighting --- src/_pytest/_io/terminalwriter.py | 4 ++++ 1 file changed, 4 insertions(+) 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(