From d393c548227d8cca441bdc6dd40b9aa6f9762120 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 05:56:46 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- changelog/11666.imporvement.rst | 2 +- src/_pytest/_io/terminalwriter.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/changelog/11666.imporvement.rst b/changelog/11666.imporvement.rst index b5cdf863b..9cb3a3b7f 100644 --- a/changelog/11666.imporvement.rst +++ b/changelog/11666.imporvement.rst @@ -2,4 +2,4 @@ Improved the terminal writer to be able to use Terminal256Formatter and Terminal These are newer versions of TerminalFormmater from the pygments library that is currently in use. -These style of these formatters are set by the users through the environmental variable PYTEST_THEME. \ No newline at end of file +These style of these formatters are set by the users through the environmental variable PYTEST_THEME. diff --git a/src/_pytest/_io/terminalwriter.py b/src/_pytest/_io/terminalwriter.py index 7e0039a32..24205177f 100644 --- a/src/_pytest/_io/terminalwriter.py +++ b/src/_pytest/_io/terminalwriter.py @@ -194,9 +194,8 @@ class TerminalWriter: for indent, new_line in zip(indents, new_lines): self.line(indent + new_line) -def _highlight( - self, source: str, lexer: Literal["diff", "python"] = "python" -) -> str: + +def _highlight(self, source: str, lexer: Literal["diff", "python"] = "python") -> str: """Highlight the given source if we have markup support.""" from _pytest.config.exceptions import UsageError @@ -219,14 +218,22 @@ def _highlight( # Terminal set to newer pygment formatters depending on user environment variables if os.getenv("COLORTERM", "") in ("truecolor", "24bit"): from pygments.formatters.terminal256 import TerminalTrueColorFormatter - terminal_formatter = TerminalTrueColorFormatter(style=os.getenv("PYTEST_THEME", "default")) + + terminal_formatter = TerminalTrueColorFormatter( + style=os.getenv("PYTEST_THEME", "default") + ) elif "256" in os.getenv("TERM", ""): from pygments.formatters.terminal256 import Terminal256Formatter - terminal_formatter = Terminal256Formatter(style=os.getenv("PYTEST_THEME", "default")) + + terminal_formatter = Terminal256Formatter( + style=os.getenv("PYTEST_THEME", "default") + ) # Otherwise use the terminal formatter used previously else: - terminal_formatter = TerminalFormatter(bg=os.getenv("PYTEST_THEME_MODE", "dark"), - style=os.getenv("PYTEST_THEME", "default")) + terminal_formatter = TerminalFormatter( + bg=os.getenv("PYTEST_THEME_MODE", "dark"), + style=os.getenv("PYTEST_THEME", "default"), + ) except ImportError: return source