[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-05-13 05:56:46 +00:00
parent 3acc7e417c
commit d393c54822
2 changed files with 15 additions and 8 deletions

View File

@ -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.
These style of these formatters are set by the users through the environmental variable PYTEST_THEME.

View File

@ -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