From d223d82372e08fcca1fa4e06eed8f4b52fe89b18 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 24 Apr 2023 11:21:33 -0600 Subject: [PATCH] Feature: suppress step timings for verbosity=1 #2891 (#2992) --- docs/changelog/2891.feature.rst | 2 ++ src/tox/session/cmd/run/common.py | 2 +- tests/session/cmd/test_sequential.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/2891.feature.rst diff --git a/docs/changelog/2891.feature.rst b/docs/changelog/2891.feature.rst new file mode 100644 index 000000000..a846cb60e --- /dev/null +++ b/docs/changelog/2891.feature.rst @@ -0,0 +1,2 @@ +When run with verbosity=1, the per-step timing summaries are suppressed at the +end of the run. Thanks to :user:`nedbat` at the PyCon 2023 sprints. diff --git a/src/tox/session/cmd/run/common.py b/src/tox/session/cmd/run/common.py index 73facf62d..49aeb87b6 100644 --- a/src/tox/session/cmd/run/common.py +++ b/src/tox/session/cmd/run/common.py @@ -174,7 +174,7 @@ def _print(color_: int, message: str) -> None: for run in runs: successful.append(run.code == Outcome.OK or run.ignore_outcome) skipped.append(run.skipped) - duration_individual = [o.elapsed for o in run.outcomes] + duration_individual = [o.elapsed for o in run.outcomes] if verbosity >= 2 else [] extra = f"+cmd[{','.join(f'{i:.2f}' for i in duration_individual)}]" if duration_individual else "" setup = run.duration - sum(duration_individual) msg, color = _get_outcome_message(run) diff --git a/tests/session/cmd/test_sequential.py b/tests/session/cmd/test_sequential.py index f3bd92312..c3e747e5a 100644 --- a/tests/session/cmd/test_sequential.py +++ b/tests/session/cmd/test_sequential.py @@ -44,6 +44,16 @@ def _cmd(value: int) -> str: assert Matches(r" a: FAIL code 1 \(.*=setup\[.*\]\+cmd\[.*\] seconds\)") == reports[-3] +def test_run_sequential_quiet(tox_project: ToxProjectCreator) -> None: + ini = "[tox]\nenv_list=a\nno_package=true\n[testenv]\ncommands=python -V" + project = tox_project({"tox.ini": ini}) + outcome = project.run("r", "-q", "-e", "a") + outcome.assert_success() + reports = outcome.out.splitlines()[-3:] + assert Matches(r" congratulations :\) \(.* seconds\)") == reports[-1] + assert Matches(r" a: OK \([\d.]+ seconds\)") == reports[-2] + + @pytest.mark.integration() def test_result_json_sequential( tox_project: ToxProjectCreator,