Skip to content

Commit 1dac11f

Browse files
fix: Respect --parallel N with --parallel-no-spinner (#3495)
* fix: Respect `--parallel N` with `--parallel-no-spinner` * add changelog entry * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix backticks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fd44904 commit 1dac11f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

docs/changelog/3495.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- ``--parallel-no-spinner`` now respects max CPU set by ``--parallel N``

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def run_parallel(state: State) -> int:
9191
option = state.conf.options
9292
return execute(
9393
state,
94-
max_workers=None if option.parallel_no_spinner is True else option.parallel,
94+
max_workers=auto_detect_cpus() if option.parallel == 0 else option.parallel,
9595
has_spinner=option.parallel_no_spinner is False and option.parallel_live is False,
9696
live=option.parallel_live,
9797
)

tests/session/cmd/test_parallel.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from tox.session.cmd.run.parallel import parse_num_processes
1515
from tox.tox_env.api import ToxEnv
1616
from tox.tox_env.errors import Fail
17+
from tox.util.cpu import auto_detect_cpus
1718

1819
if TYPE_CHECKING:
1920
from pathlib import Path
@@ -180,7 +181,20 @@ def test_parallel_no_spinner(tox_project: ToxProjectCreator) -> None:
180181

181182
mocked.assert_called_once_with(
182183
mock.ANY,
183-
max_workers=None,
184+
max_workers=auto_detect_cpus(),
185+
has_spinner=False,
186+
live=False,
187+
)
188+
189+
190+
def test_parallel_no_spinner_with_parallel(tox_project: ToxProjectCreator) -> None:
191+
"""Ensure `--parallel N` is still respected with `--parallel-no-spinner`."""
192+
with mock.patch.object(parallel, "execute") as mocked:
193+
tox_project({"tox.ini": ""}).run("p", "--parallel-no-spinner", "--parallel", "2")
194+
195+
mocked.assert_called_once_with(
196+
mock.ANY,
197+
max_workers=2,
184198
has_spinner=False,
185199
live=False,
186200
)
@@ -197,7 +211,7 @@ def test_parallel_no_spinner_ci(
197211

198212
mocked.assert_called_once_with(
199213
mock.ANY,
200-
max_workers=None,
214+
max_workers=auto_detect_cpus(),
201215
has_spinner=False,
202216
live=False,
203217
)
@@ -209,7 +223,7 @@ def test_parallel_no_spinner_legacy(tox_project: ToxProjectCreator) -> None:
209223

210224
mocked.assert_called_once_with(
211225
mock.ANY,
212-
max_workers=None,
226+
max_workers=auto_detect_cpus(),
213227
has_spinner=False,
214228
live=False,
215229
)

0 commit comments

Comments
 (0)