Skip to content

Commit

Permalink
Fix #3318 - Suppress spinner in parallel runs in CI (#3321)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernát Gábor <bgabor8@bloomberg.net>
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
  • Loading branch information
3 people authored Aug 13, 2024
1 parent 1ee4a33 commit 3b3628d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3318.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress spinner in parallel runs in CI - by :user:`ziima`.
11 changes: 9 additions & 2 deletions src/tox/session/cmd/run/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from tox.plugin import impl
from tox.session.env_select import CliEnv, register_env_select_flags
from tox.util.ci import is_ci
from tox.util.cpu import auto_detect_cpus

from .common import env_run_create_flags, execute
Expand All @@ -28,7 +29,7 @@ def tox_add_option(parser: ToxParser) -> None:
our = parser.add_command("run-parallel", ["p"], "run environments in parallel", run_parallel)
register_env_select_flags(our, default=CliEnv())
env_run_create_flags(our, mode="run-parallel")
parallel_flags(our, default_parallel=DEFAULT_PARALLEL)
parallel_flags(our, default_parallel=DEFAULT_PARALLEL, default_spinner=is_ci())


def parse_num_processes(str_value: str) -> int | None:
Expand All @@ -51,6 +52,8 @@ def parallel_flags(
our: ArgumentParser,
default_parallel: int | str,
no_args: bool = False, # noqa: FBT001, FBT002
*,
default_spinner: bool = False,
) -> None:
our.add_argument(
"-p",
Expand All @@ -75,7 +78,11 @@ def parallel_flags(
"--parallel-no-spinner",
action="store_true",
dest="parallel_no_spinner",
help="run tox environments in parallel, but don't show the spinner, implies --parallel",
default=default_spinner,
help=(
"run tox environments in parallel, but don't show the spinner, implies --parallel. "
"Disabled by default if CI is detected (not in legacy API)."
),
)


Expand Down
12 changes: 12 additions & 0 deletions tests/session/cmd/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ def test_legacy_run_sequential(tox_project: ToxProjectCreator, mocker: MockerFix
assert run_sequential.call_count == 1


def test_legacy_run_sequential_ci(
tox_project: ToxProjectCreator, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test legacy run sequential in CI by default."""
run_sequential = mocker.patch("tox.session.cmd.legacy.run_sequential")
monkeypatch.setenv("CI", "1")

tox_project({"tox.ini": ""}).run("le", "-e", "py")

assert run_sequential.call_count == 1


def test_legacy_help(tox_project: ToxProjectCreator) -> None:
outcome = tox_project({"tox.ini": ""}).run("le", "-h")
outcome.assert_success()
Expand Down
17 changes: 17 additions & 0 deletions tests/session/cmd/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ def test_parallel_no_spinner(tox_project: ToxProjectCreator) -> None:
)


def test_parallel_no_spinner_ci(
tox_project: ToxProjectCreator, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Ensure spinner is disabled by default in CI."""
mocked = mocker.patch.object(parallel, "execute")
monkeypatch.setenv("CI", "1")

tox_project({"tox.ini": ""}).run("p")

mocked.assert_called_once_with(
mock.ANY,
max_workers=None,
has_spinner=False,
live=False,
)


def test_parallel_no_spinner_legacy(tox_project: ToxProjectCreator) -> None:
with mock.patch.object(parallel, "execute") as mocked:
tox_project({"tox.ini": ""}).run("--parallel-no-spinner")
Expand Down

0 comments on commit 3b3628d

Please sign in to comment.