Skip to content

Commit a1f76cf

Browse files
chuenchen309claudepre-commit-ci[bot]
authored
Run sequentially for run-parallel -p 0 instead of at CPU count (#3989)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
1 parent 484c157 commit a1f76cf

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

docs/changelog/3989.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make ``tox run-parallel -p 0`` turn parallelism off and run sequentially, as the ``-p`` help ("zero is turn off") and
2+
the legacy command already promise, instead of running at the CPU count - by :user:`chuenchen309`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def run_parallel(state: State) -> int:
9191
raise SystemExit(msg)
9292
return execute(
9393
state,
94-
max_workers=auto_detect_cpus() if option.parallel == 0 else option.parallel,
94+
max_workers=1 if option.parallel == OFF_VALUE 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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ def test_parse_num_processes_minus_one() -> None:
4848
parse_num_processes("-1")
4949

5050

51+
def test_parallel_zero_turns_off(tox_project: ToxProjectCreator, mocker: MockerFixture) -> None:
52+
# The -p help says "zero is turn off", so -p 0 must run sequentially (one
53+
# worker) rather than auto-detecting the CPU count like -p auto.
54+
execute = mocker.patch.object(parallel, "execute", return_value=0)
55+
project = tox_project({"tox.ini": "[tox]\nno_package=true\nenv_list=a,b\n[testenv]\ncommands=python -c 'pass'\n"})
56+
project.run("p", "-p", "0")
57+
58+
assert execute.call_args.kwargs["max_workers"] == 1
59+
60+
5161
def test_parallel_general(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch, mocker: MockerFixture) -> None:
5262
def setup(self: ToxEnv) -> None:
5363
if self.name == "f":

0 commit comments

Comments
 (0)