Repository navigation
Description
Problem Description
A narrowed devops ci test run chooses its workers from the count of collected tests (#4472): up to 50 tests run serially, and more tests run on 4 workers. The count does not show the time of the tests. A module of fast tests just above the limit pays for a collection session and for the start of 4 xdist workers, and the run is about 2.5 times slower than a serial run.
Reproduction Steps
- On a host with 16 CPUs and a low load, with
PYTEST_XDIST_AUTO_NUM_WORKERSnot set, runuv run devops ci test tests/roadmap/test_roadmap_claim.py(52 tests). - Run
uv run devops ci test -n 0 tests/roadmap/test_roadmap_claim.py.
Expected vs Actual Behavior
Expected: a narrowed run of tests that take less than a second in total runs serially, and starts no collection session and no workers.
Actual: step 1 makes a collection session, then created: 4/4 workers, and takes 21.9 s to 22.3 s end to end. The 52 tests ran in 7.5 s on 4 workers. Step 2 takes 8.4 s to 8.8 s, and the 52 tests run in 0.3 s. The start of pytest (6 s to 8 s for each session) is most of the time.
Environment Diagnostics
devops-cli at the branch of #5606 (base b15faab), devcontainer, Python 3.14, pytest 9.2.0, pytest-xdist 3.8.0, load average 1.7 to 2.7 on 16 CPUs.
Logs, Traces, or Terminal Output
step 1: created: 4/4 workers ... 52 passed in 7.48s (wall 21.9 s)
step 2: 52 passed in 0.39s (wall 8.8 s)
The #5606 fix bounds the collection and skips it on a 1-CPU pod and for more than 50 target modules, but it keeps the rule of 50 collected tests, so this cost stays on hosts with more CPUs. The design of #4472 rejected a duration cache because the project keeps none. Related: #4472, #5606, #1669.
Alternatives check of 2026-11-20: none.
Tool: none found.
Reason: Searches and package facts found only pytest-xdist, pytest-split and pytest-testmon: xdist starts the explicit -n it is given and reads no durations, pytest-split needs a stored durations file to split CI groups, and testmon selects affected tests; none chooses serial versus workers for a narrowed run.
Lacks:
- No automatic serial choice from test duration
- No skip of the collection session before choosing workers
- Duration-based splitting needs a stored durations file
- No rule that one target module runs serially
Proposed design
Problem statement
A narrowed devops ci test run chooses serial versus xdist workers from the count of collected tests. A fast module just over 50 tests pays a collection session and 4 xdist workers, and the run is about 2.5 times slower than a serial run. The change makes a narrowed run to one target module serial, starts no collection session and no worker, and keeps the count rule for two or more modules and the explicit -n override.
Acceptance criteria
Requirement: Single-module narrowed run is serial
A narrowed devops ci test run with no -n and one target test module SHALL run serially and start no collection session.
Scenario: One fast module over 50 tests
- WHEN A test drives
devops ci test tests/roadmap/test_roadmap_claim.pywithPYTEST_XDIST_AUTO_NUM_WORKERSunset and records each pytest spawn. - THEN The test sees one pytest spawn with
-n 0and no spawn that holds--collect-only.
Requirement: Multi-module narrowed run keeps the count rule
A narrowed devops ci test run with no -n and two or more target modules SHALL keep the collected-test count rule.
Scenario: Two modules over the serial limit
- WHEN A test drives
devops ci testfor two target modules on a host of 16 CPUs, and the collection reports 51 tests. - THEN The test sees a spawn that holds
--collect-only, and the run spawn uses a worker count above 1.
Requirement: Explicit worker count wins
A devops ci test run with an explicit -n SHALL use that count and start no collection session.
Scenario: Explicit -n 2 on one module
- WHEN A test drives
devops ci test -n 2 tests/roadmap/test_roadmap_claim.py. - THEN The test sees one pytest spawn with
-n 2and no spawn that holds--collect-only.
Requirement: Help text states the single-module rule
The -n help text of devops ci test SHALL state that a narrowed run to one target module runs serially with no collection session.
Scenario: The -n help line
- WHEN A test runs
devops ci test --helpand reads the line of-n. - THEN The line states that a narrowed run to one target module runs serially with no collection session.
Existing Tool Considered
The alternatives check in the issue body (2026-11-20) records verdict none and no tool. The block lists what it covers and what it lacks. The change builds its own code in the existing devops ci test wrapper. It covers the lacks that the block names, because the command knows the count of target modules before pytest starts. Written cost: about 8,000 tokens to build, 1,000 tokens a month to keep and fix, and half a day elapsed.
Key questions
- Does
pytest-xdistchoose its worker count from test duration?: No.pytest-xdiststarts the explicit-nthat it is given.PYTEST_XDIST_AUTO_NUM_WORKERSaffects only-n autoand-n logical, and the command applies that value to its explicit-n. The run has no duration input. [sources: docs/TESTING.md:174, src/devops_cli/commands/ci.py] - How does the command know the count of target modules before it collects?: The command resolves the targets to test modules before it collects. The fix(ci): narrowed test workers fall back and slow runs #5606 fix already skips the collection for more than 50 target modules, so the count is known with no pytest session. [sources: src/devops_cli/commands/ci.py]
- Should the fix add a duration cache to choose workers?: No. The fix uses the count of target modules, which the command knows with no collection and no stored durations. (best practice) [sources: docs/TESTING.md:174, docs/commands/ci.md:51]
- Chosen: One-module serial rule. The command knows one target module before pytest starts, so it starts no collection session and no worker.
- Rejected: Duration cache. fix(ci): a narrowed ci test runs many slow tests serially #4472 rejected it because the project keeps no durations; it adds a write path and a first-run fallback.
- Rejected: Raise the collected-test limit. The count still does not show the time of the tests, so a slow selection over the new limit pays the same cost.
- How should a narrowed run with one target module choose workers?: Run it serially with
-n 0and skip the collection. Two or more target modules keep the existing collected-test count rule. (best practice) [sources: docs/TESTING.md:174, docs/commands/ci.md:51, src/devops_cli/config/defaults.py]- Chosen: One-module serial rule. It removes the collection session and the 4 workers from the reported 52-test module, where the pytest start is most of the 21.9 s.
- Rejected: Keep the collected-test count rule. The 52 tests collect over the 50-test limit, so the run starts 4 workers and pays the collection session.
- Rejected: Run every narrowed selection serially. It removes workers from large narrowed selections that take longer than the 6-8 s start of xdist.
- Should an explicit
-nstill override the new rule?: Yes. A given-nkeeps its worker count and gets no collection call. A person who knows that one module is slow keeps the worker count. (best practice) [sources: docs/TESTING.md:174, docs/commands/ci.md:51]- Chosen: Keep the explicit
-noverride. A person who knows that the module is slow keeps the worker count, and the change keeps the current contract. - Rejected: Let the one-module rule override
-n. It breaks the documented contract of-nand removes the escape for a slow module.
- Chosen: Keep the explicit
- Which files hold the worker choice, its defaults and its tests?:
src/devops_cli/commands/ci.pyholds the worker choice.src/devops_cli/config/defaults.pyholds the default limits.tests/commands/test_test_selection.pyholds the selection tests.docs/TESTING.mdanddocs/commands/ci.mdstate the rule. [sources: src/devops_cli/commands/ci.py, src/devops_cli/config/defaults.py, tests/commands/test_test_selection.py, docs/TESTING.md:174, docs/commands/ci.md:51] - Does the change need a new dependency or tool?: No.
pytest-xdistis already the worker runner. The change uses the existing command wrapper and the existing default limits. [sources: docs/TESTING.md:174, src/devops_cli/config/defaults.py]
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 14, 2026
Both concern worker selection for narrowed test runs, but #5606 repairs bugs in the current rule while the candidate replaces the rule with a duration-aware one.devops-cli-service commentedon Nov 18, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
devops-cli-service commentedon Nov 20, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (8)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 21, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
chore(main): release 0.220.0 (#7199)
devops-cli-service commentedon Nov 25, 2026
Released in v0.220.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.220.0
devops-cli-service commentedon Nov 25, 2026
Live since 2026-11-25 17:24 UTC