Skip to content

Commit 4e18a4f

Browse files
committed
Adds ability to configure stderr output color
1 parent ab51e14 commit 4e18a4f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/tox/config/cli/parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from pathlib import Path
1212
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Type, TypeVar, cast
1313

14+
from colorama import Fore
15+
1416
from tox.config.loader.str_convert import StrConvert
1517
from tox.plugin import NAME
1618
from tox.util.ci import is_ci
@@ -366,6 +368,12 @@ def add_color_flags(parser: ArgumentParser) -> None:
366368
choices=["yes", "no"],
367369
help="should output be enriched with colors, default is yes unless TERM=dumb or NO_COLOR is defined.",
368370
)
371+
parser.add_argument(
372+
"--stderr-color",
373+
default="RED",
374+
choices=["0", *Fore.__dict__.keys()],
375+
help="color for stderr output, use 0 to disable coloring.",
376+
)
369377

370378

371379
def add_exit_and_dump_after(parser: ArgumentParser) -> None:

src/tox/execute/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ def call(
122122
env: ToxEnv,
123123
) -> Iterator[ExecuteStatus]:
124124
start = time.monotonic()
125+
stderr_color = env.conf._conf.options.stderr_color # noqa: SLF001
126+
stderr_color = None if stderr_color == "0" else Fore.__dict__[stderr_color]
125127
try:
126128
# collector is what forwards the content from the file streams to the standard streams
127129
out, err = out_err[0].buffer, out_err[1].buffer
128130
out_sync = SyncWrite(out.name, out if show else None)
129-
err_sync = SyncWrite(err.name, err if show else None, Fore.RED if self._colored else None)
131+
err_sync = SyncWrite(err.name, err if show else None, stderr_color)
130132
with out_sync, err_sync:
131133
instance = self.build_instance(request, self._option_class(env), out_sync, err_sync)
132134
with instance as status:

0 commit comments

Comments
 (0)