feat: support pytest_plugins variable for fixture discovery#83
feat: support pytest_plugins variable for fixture discovery#83bellini666 merged 4 commits intomasterfrom
Conversation
Parse pytest_plugins module-level variable in conftest.py and test files to discover and resolve fixtures from declared modules. Supports string, list, and tuple syntax with transitive resolution. Fix #77
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #83 +/- ##
==========================================
+ Coverage 52.66% 53.09% +0.43%
==========================================
Files 26 26
Lines 2763 2829 +66
==========================================
+ Hits 1455 1502 +47
- Misses 1308 1327 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR implements support for pytest's pytest_plugins variable for fixture discovery. The feature allows fixtures to be automatically discovered from modules declared via pytest_plugins in conftest.py and test files, treating these declarations like star imports.
Changes:
- Added parsing and resolution of
pytest_pluginsvariable declarations (string, list, and tuple syntax) - Extended import scanning to include test files (
test_*.py,*_test.py) in addition to conftest.py - Implemented transitive resolution to handle chained pytest_plugins declarations
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/fixtures/imports.rs | Added extract_pytest_plugins method to parse pytest_plugins assignments and integrated pytest_plugins resolution into compute_imported_fixtures to treat them as star imports |
| src/fixtures/scanner.rs | Extended import scanning to include test files and integrated pytest_plugins extraction alongside regular imports |
| tests/test_fixtures.rs | Updated existing tests to reflect feature completion and added 8 comprehensive test cases covering single string, list, tuple, dotted paths, test file usage, transitive resolution, dynamic value handling, and available fixtures integration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e73a6bded
ℹ️ 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".
Scan venv plugins before import resolution so plugin files are in file_cache. Add site-packages fallback to resolve_absolute_import for dotted module paths like "my_plugin.internal_fixtures".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…lugins - Support `pytest_plugins: list[str] = [...]` (Stmt::AnnAssign) - Enforce last-assignment-wins when multiple pytest_plugins assignments exist in the same file, matching pytest semantics - Document pytest_plugins and star import fixture discovery in README
Summary
pytest_pluginsmodule-level variable (str,list,tuple) inconftest.pyand test files to discover fixture modulespytest_pluginsdeclarations (module A declares module B, which declares module C)pytest_plugins = get_plugins())Test plan
pytest_plugins = "module"resolves fixturespytest_plugins = ["a", "b"]resolves from both modulespytest_plugins = ("module",)works same as listpytest_plugins = "myapp.sub.fixtures"resolves nested modulespytest_pluginsintest_*.pymakes fixtures availablepytest_plugins = get_plugins()gracefully ignoredcargo clippycleanFix #77