Skip to content

Commit

Permalink
Suppress a report output when verbosity = 0. (#2774)
Browse files Browse the repository at this point in the history
* Suppress a report output when verbosity = 0.

* Use os.linesep
  • Loading branch information
q0w committed Dec 25, 2022
1 parent d8e86dd commit b0c3cf6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2697.feature.rst
@@ -0,0 +1 @@
Suppress a report output when verbosity = 0.
12 changes: 9 additions & 3 deletions src/tox/session/cmd/run/common.py
Expand Up @@ -165,9 +165,10 @@ def __call__(
)


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

successful, skipped = [], []
for run in runs:
Expand Down Expand Up @@ -250,7 +251,12 @@ def execute(state: State, max_workers: int | None, has_spinner: bool, live: bool
# write the journal
write_journal(getattr(state.conf.options, "result_json", None), state._journal)
# report the outcome
exit_code = report(state.conf.options.start, ordered_results, state.conf.options.is_colored)
exit_code = report(
state.conf.options.start,
ordered_results,
state.conf.options.is_colored,
state.conf.options.verbosity,
)
if has_previous:
signal(SIGINT, previous)
return exit_code
Expand Down
10 changes: 10 additions & 0 deletions tests/session/cmd/run/test_common.py
@@ -1,11 +1,13 @@
from __future__ import annotations

import os
import re
from argparse import ArgumentError, ArgumentParser, Namespace
from pathlib import Path

import pytest

from tox.pytest import ToxProjectCreator
from tox.session.cmd.run.common import InstallPackageAction, SkipMissingInterpreterAction


Expand Down Expand Up @@ -50,3 +52,11 @@ def test_install_pkg_empty() -> None:
argument_parser = ArgumentParser()
with pytest.raises(ArgumentError, match=re.escape("argument --install-pkg: cannot be empty")):
InstallPackageAction(option_strings=["--install-pkg"], dest="into")(argument_parser, Namespace(), "")


def test_empty_report(tox_project: ToxProjectCreator) -> None:
proj = tox_project({"tox.ini": ""})
outcome = proj.run("exec", "-qq", "--", "python", "-c", "print('foo')")

outcome.assert_success()
outcome.assert_out_err(f"foo{os.linesep}", "")

0 comments on commit b0c3cf6

Please sign in to comment.