Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2356.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve coloring of logged commands - by :user:`ssbarnea`.
2 changes: 2 additions & 0 deletions src/tox/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def format(self, record: logging.LogRecord) -> str:
if record.levelno >= logging.ERROR:
return self._error_formatter.format(record)
if record.levelno >= logging.WARNING:
if self._is_colored and record.msg == "%s%s> %s" and record.args:
record.msg = f"%s{Style.NORMAL}%s{Style.DIM}>{Style.RESET_ALL} %s"
return self._warning_formatter.format(record)
return self._remaining_formatter.format(record)

Expand Down
8 changes: 7 additions & 1 deletion tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def test_setup_report(mocker: MockerFixture, capsys: CaptureFixture, verbosity:
try:
logging.critical("critical")
logging.error("error")
logging.warning("warning")
# special warning line that should be auto-colored
logging.warning("%s%s> %s", "warning", "foo", "bar")
logging.info("info")
logging.debug("debug")
logging.log(logging.NOTSET, "not-set") # this should not be logged
Expand Down Expand Up @@ -56,5 +57,10 @@ def test_setup_report(mocker: MockerFixture, capsys: CaptureFixture, verbosity:

if color:
assert f"{Style.RESET_ALL}" in out
# check that our Warning line using special format was colored
expected_warning_text = "W\x1b[0m\x1b[36m warning\x1b[22mfoo\x1b[2m>\x1b[0m bar\x1b[0m\x1b[2m"
else:
assert f"{Style.RESET_ALL}" not in out
expected_warning_text = "warningfoo> bar"
if verbosity >= 4: # where warnings are logged
assert expected_warning_text in lines[3]