Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress a report output when verbosity = 0. #2774

Merged
merged 2 commits into from Dec 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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}", "")