Repository navigation
fix(devtools): expose pytest selection during verify - #2107
Conversation
Problem: a slow or stalled selected pytest run exposed only the active node and stream output, leaving agents to infer whether testmon selected the wrong set or whether time was spent in collection, setup, call, or teardown. That made harness slowness hard to diagnose and encouraged ad hoc reruns.\n\nWhat changed: the pytest progress plugin now writes a current-pytest-selection.json artifact with selected and deselected node IDs, records collection summaries in the event stream, and logs setup/call/teardown phase reports. devtools verify and devtools test both pass the selection artifact path through their managed environments and report it next to the existing progress/events/output files.\n\nVerification: devtools test tests/unit/devtools/test_pytest_progress_plugin.py tests/unit/devtools/test_run_tests.py -n 0; ruff format --check devtools/pytest_progress_plugin.py devtools/verify.py devtools/run_tests.py tests/unit/devtools/test_pytest_progress_plugin.py; ruff check devtools/pytest_progress_plugin.py devtools/verify.py devtools/run_tests.py tests/unit/devtools/test_pytest_progress_plugin.py; devtools verify --quick
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe pytest progress plugin gains a selection ledger: new module state tracks deselected node IDs, a ChangesPytest selection ledger
Sequence Diagram(s)sequenceDiagram
participant verify as verify.py / run_tests.py
participant pytest_sub as pytest subprocess
participant plugin as pytest_progress_plugin
participant sel_json as current-pytest-selection.json
participant event_log as event log (JSONL)
verify->>verify: delete stale current-pytest-selection.json
verify->>pytest_sub: launch with POLYLOGUE_PYTEST_SELECTION_PATH set
pytest_sub->>plugin: pytest_deselected(items)
plugin->>plugin: accumulate _DESELECTED_NODEIDS
pytest_sub->>plugin: pytest_collection_modifyitems(session, items)
plugin->>sel_json: write {selected_count, deselected_count, selected_nodeids, deselected_nodeids}
plugin->>event_log: append collection_finished event
pytest_sub->>plugin: pytest_runtest_logreport(report) [setup/call/teardown]
plugin->>event_log: append test_report event
pytest_sub-->>verify: exit
verify->>sel_json: read selected_count, deselected_count
verify->>verify: record counts in step metadata
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a11465f4aa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @pytest.hookimpl(trylast=True) | ||
| def pytest_collection_modifyitems(session: Any, config: Any, items: list[Any]) -> None: |
There was a problem hiding this comment.
Write selection after testmon prunes items
In the default devtools verify path, devtools/verify.py:776 runs pytest with --testmon; pytest-testmon's selector is also a trylast pytest_collection_modifyitems registered during configuration. Because this hook is registered earlier, it can run before testmon mutates items and emits its deselections, so current-pytest-selection.json reports the pre-testmon selected set and misses the deselected tests in exactly the affected-test lane this artifact is meant to explain. Write the artifact from a hookwrapper after yield or a later collection hook so it observes the final item list.
Useful? React with 👍 / 👎.
Summary
Adds explicit pytest selection observability to the managed
devtools verify/devtools testharness. Slow or stalled runs now leave acurrent-pytest-selection.jsonartifact alongside the existing progress, event, and output ledgers.Problem
The harness could report the active pytest node and terminate stalled child process groups, but it did not preserve the selected/deselected node set or phase-level timing. That made it hard to distinguish a genuinely slow test from a bad testmon selection, expensive collection, or fixture/setup hang.
Solution
The pytest progress plugin now writes
.cache/verify/current-pytest-selection.jsonwith selected and deselected node IDs, emits a collection summary event, and records setup/call/teardown reports instead of only call reports and failures.devtools verifyanddevtools testboth pass the selection path through their managed environments and surface the artifact path in metadata/output.Verification
devtools test tests/unit/devtools/test_pytest_progress_plugin.py tests/unit/devtools/test_run_tests.py -n 0devtools test tests/unit/devtools/test_pytest_progress_plugin.py -k records_node -n 0and read back.cache/verify/current-pytest-selection.jsonruff format --check devtools/pytest_progress_plugin.py devtools/verify.py devtools/run_tests.py tests/unit/devtools/test_pytest_progress_plugin.pyruff check devtools/pytest_progress_plugin.py devtools/verify.py devtools/run_tests.py tests/unit/devtools/test_pytest_progress_plugin.pydevtools verify --quickSummary by CodeRabbit