[tests] fix --write-outputs pytest option discovery#290
Conversation
Move pytest_addoption() and pytest_configure() hooks from the deeply-nested engine/conftest.py to a root-level conftest.py. Pytest discovers conftest.py via the rootdir and testpaths configuration during plugin loading, before argument parsing. The engine conftest was never being loaded because: 1. No root-level conftest.py exists 2. No testpaths configuration guides pytest to engine/ 3. Pytest doesn't walk arbitrary src/ subdirectories By placing the hook implementations at the project root, pytest discovers them early and registers the --write-outputs option before argparse runs, allowing the flag to be recognized.
…ker levels (#251) Fixes two critical issues with pytest option registration: 1. Root-level conftest.py not shipped to container: Updated osprey_worker/Dockerfile to ADD the root conftest.py during build, ensuring --write-outputs is available when the test_runner container invokes pytest. 2. pytest rootdir shifts with sub-path invocation: Placed identical hook implementations at both conftest.py (root) and osprey_worker/conftest.py so the option is registered regardless of whether pytest is invoked from the worktree root or from within osprey_worker/ subdirectories. Added try/except logic to gracefully handle the option already being registered by the other conftest.py file. Also removed unused TYPE_CHECKING imports for Config and Parser from osprey_worker/src/osprey/engine/conftest.py, as the hook logic that used them was moved to the conftest.py files. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…aths (#251) Replace the two-conftest-with-try/except pattern with a single source of truth: - Add [tool.pytest.ini_options].testpaths = ["osprey_worker"] to root pyproject.toml, which pins pytest rootdir to the worktree root while telling pytest where to look for tests. This ensures osprey_worker/conftest.py is loaded during plugin discovery regardless of invocation path. - Delete root conftest.py — no longer needed. osprey_worker/conftest.py is now the sole source for --write-outputs registration and markers. - Remove the try/except ValueError wrapper around parser.addoption in osprey_worker/conftest.py. No double-registration is possible now. - Revert the ADD conftest.py line in osprey_worker/Dockerfile (line 31). - Format osprey_worker/src/osprey/engine/conftest.py for ruff compliance. Verification: all four pytest invocation modes accept --write-outputs from root and osprey_worker/ without errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThis PR relocates pytest configuration from a nested ChangesPytest Configuration Relocation
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
The license excerpt is usually inserted in every file created, but I noticed that's not the case here, is this for consistency as no file in the repo has the excerpt?
|
Tested all four invocation modes, works as expected. |
Summary
./run-tests.sh --write-outputswas failing withpytest: error: unrecognized arguments: --write-outputsbecause the option was declared inosprey_worker/src/osprey/engine/conftest.py— pytest never discovers conftests that deep before plugin-loading argparse runs. Move the option registration toosprey_worker/conftest.pyand addtestpaths = ["osprey_worker"]to rootpyproject.tomlso pytest discovers it from any invocation directory.Related Issues/Tasks
Closes #251
Changes Made
osprey_worker/conftest.pywithpytest_addoption(--write-outputs)andpytest_configure()(registers project markers).osprey_worker/src/osprey/engine/conftest.py— fixtures remain in place.[tool.pytest.ini_options].testpaths = ["osprey_worker"]to rootpyproject.toml. This pins rootdir at the worktree root for path-less invocations AND makes pytest's conftest walk findosprey_worker/conftest.pyduring plugin discovery. The same file is also rootdir for path-scoped invocations insideosprey_worker/, so all four invocation paths work without duplication.Confidence Level
Confidence Level: Claude
Testing
Verified four pytest invocation modes accept
--write-outputs:uv run pytest --write-outputs --collect-only -qfrom worktree root (no path)uv run pytest osprey_worker/src/osprey/engine/query_language/tests/test_ast_druid_translator.py --write-outputs --collect-only -qfrom worktree rootcd osprey_worker && uv run pytest --write-outputs --collect-only -qcd osprey_worker && uv run pytest src/osprey/engine/query_language/tests/test_ast_druid_translator.py --write-outputs --collect-only -qAlso:
uv run ruff format --check .— passes.uv run ruff check osprey_worker/conftest.py osprey_worker/src/osprey/engine/conftest.py— clean.uv run pytest --collect-only -qstill collects 1127 tests.Cycle notes
This branch went through three review cycles. The first attempt put
conftest.pyat the worktree root but the file wasn't shipped into the test_runner container and rootdir shifted forosprey_worker/-scoped invocations. The second attempt duplicated conftest files withtry/exceptguards. This final shape adopts the reviewer's recommended single-source-of-truth viatestpaths.Summary by CodeRabbit
--write-outputscommand-line option for test execution.