Skip to content

Fix source-tree unittest imports#118

Merged
peaktwilight merged 1 commit into
mainfrom
fix/source-tree-unittest-imports
May 24, 2026
Merged

Fix source-tree unittest imports#118
peaktwilight merged 1 commit into
mainfrom
fix/source-tree-unittest-imports

Conversation

@Darkroom4364

@Darkroom4364 Darkroom4364 commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • apply the shared test path setup when importing the tests package
  • align tests/_pathfix.py with local CI by adding both repo root and src to sys.path
  • add a subprocess regression for the targeted unittest command from [CI] Fix source-tree local test parity for unittest imports #114
  • document targeted unittest behavior in CONTRIBUTING.md

Closes #114.

Tests

  • python3 -m unittest tests.test_public_claim_artifacts tests.test_operator_surface tests.test_package_metadata
  • PYTHONPATH=src python3 -m unittest tests.test_operator_surface
  • python3 -m unittest tests.test_ci_local_script tests.test_contributor_setup_docs
  • git diff --check

Not run: python3 -m pytest tests/test_ci_local_script.py tests/test_operator_surface.py tests/test_contributor_setup_docs.py -q because pytest is not installed in the local Python environment.

Summary by CodeRabbit

  • Documentation

    • Updated contribution guide with improved clarity on executing targeted test commands directly from the source tree, including guidance on PYTHONPATH configuration.
  • Tests

    • Enhanced test execution infrastructure to support running tests from the source tree without requiring an editable package installation.
    • Added continuous integration verification for source-tree test execution.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1793d573-2503-413d-8aa3-a0ab92c711d1

📥 Commits

Reviewing files that changed from the base of the PR and between 295c887 and de95c3d.

📒 Files selected for processing (4)
  • CONTRIBUTING.md
  • tests/__init__.py
  • tests/_pathfix.py
  • tests/test_ci_local_script.py

📝 Walkthrough

Walkthrough

The PR enables direct source-tree unittest invocations by automatically setting up sys.path when the tests package is imported. The repository root is added to sys.path alongside the existing src directory, and this setup is triggered via a side-effect import in tests/__init__.py. A new validation test confirms the behavior works without PYTHONPATH, and contributor documentation clarifies the intended invocation pattern.

Changes

Source-tree unittest path setup and validation

Layer / File(s) Summary
Repository root path setup and automatic activation
tests/_pathfix.py, tests/__init__.py
tests._pathfix now inserts repository root into sys.path if missing; tests.__init__ imports _pathfix as a side-effect during package import, with module docstring explaining the behavior for python -m unittest discovery.
Source-tree unittest validation test
tests/test_ci_local_script.py
New test method test_targeted_unittest_imports_work_from_source_tree verifies targeted unittest modules execute successfully from repository root without PYTHONPATH set, using sys.executable to invoke the interpreter and capturing subprocess output.
Contributor documentation update
CONTRIBUTING.md
Clarifies that tests.* unittest runs automatically apply source-tree path setup when tests package is imported, while CLI commands and scripts still require explicit PYTHONPATH export unless using editable install.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A path through the source, now clear as can be,
The tests find their modules, no PYTHONPATH decree!
Root and source intertwined, in sys.path they go,
With __init__ importing, the setup steals the show. ✨

🚥 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 pull request title 'Fix source-tree unittest imports' directly summarizes the main objective of addressing local test execution failures without PYTHONPATH setup.
Linked Issues check ✅ Passed The pull request successfully addresses all acceptance criteria from issue #114: the targeted unittest command now works from source tree, PYTHONPATH=src variant continues to work, and contributor documentation is updated.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #114 objectives: shared test path setup, sys.path configuration, regression test, and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix/source-tree-unittest-imports

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.

❤️ Share

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

@peaktwilight peaktwilight merged commit 99b3f73 into main May 24, 2026
2 checks passed
@peaktwilight peaktwilight deleted the fix/source-tree-unittest-imports branch May 24, 2026 13:50
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.

[CI] Fix source-tree local test parity for unittest imports

2 participants