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

Fix #3318 - Suppress spinner in parallel runs in CI #3321

Merged
merged 3 commits into from
Aug 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading