Skip to content

feat: support pytest_plugins variable for fixture discovery#83

Merged
bellini666 merged 4 commits intomasterfrom
feat/pytest-plugins-variable
Feb 14, 2026
Merged

feat: support pytest_plugins variable for fixture discovery#83
bellini666 merged 4 commits intomasterfrom
feat/pytest-plugins-variable

Conversation

@bellini666
Copy link
Copy Markdown
Owner

Summary

  • Parse pytest_plugins module-level variable (str, list, tuple) in conftest.py and test files to discover fixture modules
  • Resolve declared modules and treat them as star imports, making their fixtures available to go-to-definition, completions, hover, and references
  • Handle transitive pytest_plugins declarations (module A declares module B, which declares module C)
  • Gracefully ignore dynamic values (e.g. pytest_plugins = get_plugins())

Test plan

  • Single string: pytest_plugins = "module" resolves fixtures
  • List syntax: pytest_plugins = ["a", "b"] resolves from both modules
  • Tuple syntax: pytest_plugins = ("module",) works same as list
  • Dotted paths: pytest_plugins = "myapp.sub.fixtures" resolves nested modules
  • Test file usage: pytest_plugins in test_*.py makes fixtures available
  • Transitive resolution: conftest → module_b → module_c all discovered
  • Dynamic values: pytest_plugins = get_plugins() gracefully ignored
  • Available fixtures integration: fixtures appear in completions
  • All 273 existing tests still pass
  • cargo clippy clean

Fix #77

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
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 14, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 63.88889% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.09%. Comparing base (e5f6c79) to head (b41324e).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/fixtures/imports.rs 57.44% 20 Missing ⚠️
src/fixtures/scanner.rs 75.00% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_plugins variable 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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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
@bellini666 bellini666 merged commit 9c5cd5e into master Feb 14, 2026
20 checks passed
@bellini666 bellini666 deleted the feat/pytest-plugins-variable branch February 14, 2026 13:48
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.

Support pytest_plugins Variable for Fixture Discovery

2 participants