Skip to content

Commit b0c3cf6

Browse files
authored
Suppress a report output when verbosity = 0. (#2774)
* Suppress a report output when verbosity = 0. * Use os.linesep
1 parent d8e86dd commit b0c3cf6

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

docs/changelog/2697.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Suppress a report output when verbosity = 0.

src/tox/session/cmd/run/common.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ def __call__(
165165
)
166166

167167

168-
def report(start: float, runs: list[ToxEnvRunResult], is_colored: bool) -> int:
168+
def report(start: float, runs: list[ToxEnvRunResult], is_colored: bool, verbosity: int) -> int:
169169
def _print(color_: int, message: str) -> None:
170-
print(f"{color_ if is_colored else ''}{message}{Fore.RESET if is_colored else ''}")
170+
if verbosity:
171+
print(f"{color_ if is_colored else ''}{message}{Fore.RESET if is_colored else ''}")
171172

172173
successful, skipped = [], []
173174
for run in runs:
@@ -250,7 +251,12 @@ def execute(state: State, max_workers: int | None, has_spinner: bool, live: bool
250251
# write the journal
251252
write_journal(getattr(state.conf.options, "result_json", None), state._journal)
252253
# report the outcome
253-
exit_code = report(state.conf.options.start, ordered_results, state.conf.options.is_colored)
254+
exit_code = report(
255+
state.conf.options.start,
256+
ordered_results,
257+
state.conf.options.is_colored,
258+
state.conf.options.verbosity,
259+
)
254260
if has_previous:
255261
signal(SIGINT, previous)
256262
return exit_code

tests/session/cmd/run/test_common.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import annotations
22

3+
import os
34
import re
45
from argparse import ArgumentError, ArgumentParser, Namespace
56
from pathlib import Path
67

78
import pytest
89

10+
from tox.pytest import ToxProjectCreator
911
from tox.session.cmd.run.common import InstallPackageAction, SkipMissingInterpreterAction
1012

1113

@@ -50,3 +52,11 @@ def test_install_pkg_empty() -> None:
5052
argument_parser = ArgumentParser()
5153
with pytest.raises(ArgumentError, match=re.escape("argument --install-pkg: cannot be empty")):
5254
InstallPackageAction(option_strings=["--install-pkg"], dest="into")(argument_parser, Namespace(), "")
55+
56+
57+
def test_empty_report(tox_project: ToxProjectCreator) -> None:
58+
proj = tox_project({"tox.ini": ""})
59+
outcome = proj.run("exec", "-qq", "--", "python", "-c", "print('foo')")
60+
61+
outcome.assert_success()
62+
outcome.assert_out_err(f"foo{os.linesep}", "")

0 commit comments

Comments
 (0)