Honor discovery_args on single-pass pytest discovery (OFFLOAD-9) - #252
Merged
Conversation
Mark code-ksar in progress and record the OFFLOAD-9 linkage, plan, and acceptance criteria: make single-pass collect_pool honor discovery_args and env/prepend_path exactly as the legacy discover path. Co-authored-by: Sculptor <sculptor@imbue.com>
The single-pass discovery path (`PytestFramework::collect_pool`) built its pooled `pytest --collect-only` command without the framework's `discovery_args` or its `env`/`prepend_path`, so `offload collect` silently ignored those settings even though the legacy per-group `discover` path applied them. This closed a parity gap for OFFLOAD-9. collect_pool now injects `discovery_args` right after `--collect-only -q` and before the hoisted filter args (matching the legacy ordering) and calls `apply_discovery_env` before setting the plugin `PYTHONPATH`/config env, so the `offload_partition` plugin remains authoritative. The `discovery_args` tokenization is extracted into a shared `discovery_args_tokens` helper used by both discovery paths to prevent drift. A new end-to-end parity scenario sets `discovery_args = "--ignore examples/tests/sub"` over a poolable group set; it passes with the fix and fails without it (single-pass would otherwise collect the ignored subdir). Co-authored-by: Sculptor <sculptor@imbue.com>
code-ksar (OFFLOAD-9) passed Judge review. File follow-ups surfaced as non-blocking observations: code-8d97 (harden collect_pool env/prepend_path PYTHONPATH handling plus a regression guard) and code-18z3 (reconcile the collect_only_command doc and PYTHONDONTWRITEBYTECODE between the legacy and single-pass discovery paths). Co-authored-by: Sculptor <sculptor@imbue.com>
…paths Mark code-18z3 in progress and record the chosen approach: make legacy discover derive its command base from collect_only_command so the "shared by both paths" doc becomes true and PYTHONDONTWRITEBYTECODE is applied consistently. Co-authored-by: Sculptor <sculptor@imbue.com>
Legacy discover now derives its command from collect_only_command, reusing the same program, prefix, --collect-only -q, and PYTHONDONTWRITEBYTECODE=1 as the single-pass pool, so throwaway collection no longer writes __pycache__ and the helper's "shared by both discovery paths" docstring holds. A new discovery_extra_args helper is the single source of truth for the discovery_args/filters/paths tail, used by both the executed command and its display string; the now-redundant discovery_cmd_args is removed, its coverage ported onto the tail helper plus a collect_only_command base test. Refs: code-18z3 Co-authored-by: Sculptor <sculptor@imbue.com>
…d base Judge PASS: legacy discover now derives its command base from collect_only_command (shared with collect_pool), so the helper doc is accurate and legacy discovery sets PYTHONDONTWRITEBYTECODE. code-ksar wiring verified intact; DoD green (415 tests). Co-authored-by: Sculptor <sculptor@imbue.com>
… honoring Record the approved de-complected design: extract build_pool_command from collect_pool, honor a config env.PYTHONPATH (scripts_dir first, then config value else ambient), and lock the pool command args/env with one as_std test. Co-authored-by: Sculptor <sculptor@imbue.com>
…THONPATH
Extract the pool command+env assembly out of collect_pool into a pure
build_pool_command(scripts_dir, cfg_path, hoisted_args, search_paths) so it
can be unit-tested without launching pytest; collect_pool keeps the temp-file
lifetimes, serialization, scripts_dir lookup, output, and report parsing.
The seam also folds a config env.PYTHONPATH into PYTHONPATH instead of dropping
it: build_pythonpath now takes an optional base, and the pool command resolves
{root} in the config value against cwd (reusing resolve_root_placeholder) so
PYTHONPATH is scripts_dir first (plugin import) then the config value when set,
else the ambient process PYTHONPATH. A new as_std unit test locks the pool
command args and env (discovery_args, -p offload_partition, resolved env, the
prepend-merged PATH, PYTHONPATH base-selection, and OFFLOAD_PARTITION_CONFIG).
Refs: code-8d97
Co-authored-by: Sculptor <sculptor@imbue.com>
Judge PASS: collect_pool now builds via build_pool_command, single-pass honors a config env.PYTHONPATH (scripts_dir kept first for the plugin), and one as_std test locks the pool command args/env. DoD green (416 tests); no regression to code-ksar/code-18z3. Co-authored-by: Sculptor <sculptor@imbue.com>
Track the /crispy-comments cleanup of the OFFLOAD-9 branch diff: trim comments that restate code, enumerate call sites or base contents, or carry a correctness argument plus a rot-prone count. Co-authored-by: Sculptor <sculptor@imbue.com>
Apply the crispy-comments pass for code-96xf: collapse restated or over-detailed doc and inline comments on the shared pytest discovery seam and drop a rot-prone count from the parity test doc. Comment-only; no logic, behavior, or code-whitespace changes. Co-authored-by: Sculptor <sculptor@imbue.com>
Judge PASS: comment-only diff (code byte-identical), the eight redundant comments trimmed, keep-list intact, DoD green (416 tests). Co-authored-by: Sculptor <sculptor@imbue.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Linear: OFFLOAD-9 — a first-class discovery-args knob for scoped pytest discovery.
offloadalready exposed a[framework].discovery_argsconfig field (the discovery-side mirror ofrun_args), but only the legacy per-group discovery path applied it. The single-pass discovery path — the oneoffload collectactually uses — silently ignoreddiscovery_args,env, andprepend_path. This PR closes that gap and hardens the two discovery paths so they can no longer drift.Net effect: a repo can move discovery-only args (e.g.
-c pyproject.toml, to pin pytest's rootdir/config) out of a group'sfiltersand into[framework].discovery_args, andoffload collectwill honor them — keeping discovered test ids stable regardless of scopedpaths.What changed
1. Single-pass discovery honors
discovery_args+env/prepend_pathcollect_poolnow injectsdiscovery_args(before the hoisted filters, matching legacy order) and appliesapply_discovery_env(env, prepend_path), mirroring the legacydiscoverpath. A new end-to-end parity scenario (single_pass_honors_discovery_args) guards it.2. Legacy
discovershares the collect-only command basediscovernow derives its command from the sharedcollect_only_command()helper (program, prefix,--collect-only -q,PYTHONDONTWRITEBYTECODE=1), so both discovery paths build from one base and legacy discovery no longer writes__pycache__. A newdiscovery_extra_argshelper is the single source for the command tail (discovery_args→ filters → search paths), consumed by both the executed command and its error-display string so they can't diverge.3.
collect_poolcommand seam + honor configenv.PYTHONPATHExtracted
build_pool_command(...)as the single, unit-testable home for the pool command/env assembly.build_pythonpathnow honors a configenv.PYTHONPATH(the bundledoffload_partitionplugin dir stays first onPYTHONPATHso it still imports; the config value is folded in as the base instead of being dropped) — removing a single-pass-vs-legacy divergence. Locked by anas_std()unit test.4. Comment cleanup
Pruned redundant comments on the touched discovery paths (call-site enumerations, base-content restatements, and a correctness argument carrying a rot-prone count).
Testing
cargo fmt --check,cargo clippy --all-targets --all-features(no warnings),cargo nextest run(416 passed, 0 skipped), andratchets check— all green.examples/testsand asserts byte-identical per-group ids across all scenarios (with real pytest viauv).Result
One shared command base (
collect_only_command), onediscovery_argstokenizer, one legacy tail (discovery_extra_args), and one pool-command home (build_pool_command) — the drift surface that caused the original bug is largely gone. Work was tracked as beads code-ksar, code-18z3, code-8d97, and code-96xf.🤖 Generated with Claude Code