Skip to content

[tests] fix --write-outputs pytest option discovery#290

Open
haileyok wants to merge 3 commits into
mainfrom
claude/bug-251-write-outputs
Open

[tests] fix --write-outputs pytest option discovery#290
haileyok wants to merge 3 commits into
mainfrom
claude/bug-251-write-outputs

Conversation

@haileyok
Copy link
Copy Markdown
Member

@haileyok haileyok commented May 23, 2026

Summary

./run-tests.sh --write-outputs was failing with pytest: error: unrecognized arguments: --write-outputs because the option was declared in osprey_worker/src/osprey/engine/conftest.py — pytest never discovers conftests that deep before plugin-loading argparse runs. Move the option registration to osprey_worker/conftest.py and add testpaths = ["osprey_worker"] to root pyproject.toml so pytest discovers it from any invocation directory.

Related Issues/Tasks

Closes #251

Changes Made

  • Created osprey_worker/conftest.py with pytest_addoption(--write-outputs) and pytest_configure() (registers project markers).
  • Removed those hooks from osprey_worker/src/osprey/engine/conftest.py — fixtures remain in place.
  • Added [tool.pytest.ini_options].testpaths = ["osprey_worker"] to root pyproject.toml. This pins rootdir at the worktree root for path-less invocations AND makes pytest's conftest walk find osprey_worker/conftest.py during plugin discovery. The same file is also rootdir for path-scoped invocations inside osprey_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 -q from worktree root (no path)
  • uv run pytest osprey_worker/src/osprey/engine/query_language/tests/test_ast_druid_translator.py --write-outputs --collect-only -q from worktree root
  • cd osprey_worker && uv run pytest --write-outputs --collect-only -q
  • cd osprey_worker && uv run pytest src/osprey/engine/query_language/tests/test_ast_druid_translator.py --write-outputs --collect-only -q

Also:

  • uv run ruff format --check . — passes.
  • uv run ruff check osprey_worker/conftest.py osprey_worker/src/osprey/engine/conftest.py — clean.
  • Default uv run pytest --collect-only -q still collects 1127 tests.

Cycle notes

This branch went through three review cycles. The first attempt put conftest.py at the worktree root but the file wasn't shipped into the test_runner container and rootdir shifted for osprey_worker/-scoped invocations. The second attempt duplicated conftest files with try/except guards. This final shape adopts the reviewer's recommended single-source-of-truth via testpaths.

Summary by CodeRabbit

  • Chores
    • Reorganized pytest configuration infrastructure by consolidating root-level test setup and configuration.
    • Added custom pytest markers for validators, UDF registry, and version-specific output testing.
    • Implemented --write-outputs command-line option for test execution.
    • Updated project configuration to standardize test discovery paths.

Review Change Stack

haileyok and others added 3 commits May 23, 2026 00:06
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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d65b0a9-7480-47e3-a366-97793c321a64

📥 Commits

Reviewing files that changed from the base of the PR and between 615ac01 and f9dc062.

📒 Files selected for processing (3)
  • osprey_worker/conftest.py
  • osprey_worker/src/osprey/engine/conftest.py
  • pyproject.toml
💤 Files with no reviewable changes (1)
  • osprey_worker/src/osprey/engine/conftest.py

📝 Walkthrough

Walkthrough

This PR relocates pytest configuration from a nested conftest.py to the root osprey_worker/conftest.py, registers the --write-outputs command-line option and custom pytest markers at the root level, constrains test discovery to the osprey_worker directory in pyproject.toml, and removes the duplicate hook implementations from the nested location.

Changes

Pytest Configuration Relocation

Layer / File(s) Summary
Root conftest with pytest hooks
osprey_worker/conftest.py
New root-level conftest implements pytest_addoption to register --write-outputs option and pytest_configure to register custom markers (use_validators, use_standard_rules_validators, inject_validator_result, use_udf_registry, use_osprey_stdlib, vary_output_by_py_version) via type-guarded imports.
Test discovery configuration
pyproject.toml
Adds [tool.pytest.ini_options] section with testpaths = ["osprey_worker"] to constrain pytest test discovery to the osprey_worker directory.
Nested conftest cleanup
osprey_worker/src/osprey/engine/conftest.py
Removes _pytest.config.Config and _pytest.config.argparsing.Parser from TYPE_CHECKING imports and deletes the duplicate pytest_addoption and pytest_configure hook functions.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[tests] fix --write-outputs pytest option discovery' directly describes the main change: moving pytest option registration to ensure discovery before argparse runs.
Linked Issues check ✅ Passed The PR fulfills all requirements from #251: registers --write-outputs in root conftest for early discovery, adds testpaths to ensure discovery, verified across all invocation modes, and preserves test behavior.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the --write-outputs discovery issue: root conftest registration, engine conftest cleanup, and testpaths configuration with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/bug-251-write-outputs

Comment @coderabbitai help to get the list of available commands and usage tips.

@haileyok haileyok marked this pull request as ready for review May 23, 2026 00:57
@haileyok haileyok requested review from a team, EXBreder, ayubun and vinaysrao1 as code owners May 23, 2026 00:57
Comment thread conftest.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@chimosky
Copy link
Copy Markdown
Contributor

Tested all four invocation modes, works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--write-outputs is unrecognized while running tests

2 participants