-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
Summary
Implement automatic resolution and loading of fixtures declared via the pytest_plugins variable at module level.
Background
Pytest supports a pytest_plugins variable that allows users to declare fixture modules that should be loaded. This is commonly used in conftest.py files to import fixtures from external modules or packages without explicit imports.
# conftest.py
pytest_plugins = ["myapp.fixtures", "other.fixtures"]Currently, the language server does not resolve these declarations, meaning fixtures from pytest_plugins modules are not discoverable for go-to-definition, completions, or other LSP features.
Requirements
Supported Syntax
All valid pytest_plugins syntax forms should be supported:
- Single string:
pytest_plugins = "myapp.fixtures" - List:
pytest_plugins = ["module1", "module2"] - Tuple:
pytest_plugins = ("module1", "module2")
Supported Locations
The pytest_plugins variable should be parsed in:
- conftest.py - Plugin registration for all tests in the directory tree
- Test files (
test_*.py,*_test.py) - File-specific plugins - Plugin entry point modules - Transitive plugin loading
Resolution Logic
- Parse
pytest_pluginsassignments during file analysis - Extract only static string literals (expressions/variables should be skipped since they can't be resolved statically)
- Resolve module paths to actual files using the same logic as imports
- Recursively analyze plugin modules for fixtures
- Recursively process any
pytest_pluginsdeclarations in those modules (transitive loading)
Limitations
- Dynamic values not supported: If
pytest_pluginsis assigned a variable, function call, or any non-literal expression, it will be skipped - Conditional declarations not supported:
pytest_pluginsinsideifblocks will not be detected (consistent with other fixture limitations)
Expected Outcome
# conftest.py
pytest_plugins = ["myapp.fixtures", "other.fixtures"]
# test_example.py
def test_something(fixture_from_myapp):
# Go-to-definition on fixture_from_myapp should work
# Completions should suggest fixtures from myapp.fixtures
passReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels