Skip to content

Commit 3b3628d

Browse files
ziimagaborbernat
andauthored
Fix #3318 - Suppress spinner in parallel runs in CI (#3321)
Co-authored-by: Bernát Gábor <[email protected]> Co-authored-by: Bernát Gábor <[email protected]>
1 parent 1ee4a33 commit 3b3628d

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

docs/changelog/3318.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Suppress spinner in parallel runs in CI - by :user:`ziima`.

src/tox/session/cmd/run/parallel.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from tox.plugin import impl
1010
from tox.session.env_select import CliEnv, register_env_select_flags
11+
from tox.util.ci import is_ci
1112
from tox.util.cpu import auto_detect_cpus
1213

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

3334

3435
def parse_num_processes(str_value: str) -> int | None:
@@ -51,6 +52,8 @@ def parallel_flags(
5152
our: ArgumentParser,
5253
default_parallel: int | str,
5354
no_args: bool = False, # noqa: FBT001, FBT002
55+
*,
56+
default_spinner: bool = False,
5457
) -> None:
5558
our.add_argument(
5659
"-p",
@@ -75,7 +78,11 @@ def parallel_flags(
7578
"--parallel-no-spinner",
7679
action="store_true",
7780
dest="parallel_no_spinner",
78-
help="run tox environments in parallel, but don't show the spinner, implies --parallel",
81+
default=default_spinner,
82+
help=(
83+
"run tox environments in parallel, but don't show the spinner, implies --parallel. "
84+
"Disabled by default if CI is detected (not in legacy API)."
85+
),
7986
)
8087

8188

tests/session/cmd/test_legacy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def test_legacy_run_sequential(tox_project: ToxProjectCreator, mocker: MockerFix
121121
assert run_sequential.call_count == 1
122122

123123

124+
def test_legacy_run_sequential_ci(
125+
tox_project: ToxProjectCreator, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
126+
) -> None:
127+
"""Test legacy run sequential in CI by default."""
128+
run_sequential = mocker.patch("tox.session.cmd.legacy.run_sequential")
129+
monkeypatch.setenv("CI", "1")
130+
131+
tox_project({"tox.ini": ""}).run("le", "-e", "py")
132+
133+
assert run_sequential.call_count == 1
134+
135+
124136
def test_legacy_help(tox_project: ToxProjectCreator) -> None:
125137
outcome = tox_project({"tox.ini": ""}).run("le", "-h")
126138
outcome.assert_success()

tests/session/cmd/test_parallel.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ def test_parallel_no_spinner(tox_project: ToxProjectCreator) -> None:
186186
)
187187

188188

189+
def test_parallel_no_spinner_ci(
190+
tox_project: ToxProjectCreator, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
191+
) -> None:
192+
"""Ensure spinner is disabled by default in CI."""
193+
mocked = mocker.patch.object(parallel, "execute")
194+
monkeypatch.setenv("CI", "1")
195+
196+
tox_project({"tox.ini": ""}).run("p")
197+
198+
mocked.assert_called_once_with(
199+
mock.ANY,
200+
max_workers=None,
201+
has_spinner=False,
202+
live=False,
203+
)
204+
205+
189206
def test_parallel_no_spinner_legacy(tox_project: ToxProjectCreator) -> None:
190207
with mock.patch.object(parallel, "execute") as mocked:
191208
tox_project({"tox.ini": ""}).run("--parallel-no-spinner")

0 commit comments

Comments
 (0)