feat: support pytestmark = pytest.mark.usefixtures for fixture usage#91
Conversation
Add autocomplete in usefixtures context.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #91 +/- ##
==========================================
+ Coverage 55.45% 56.28% +0.82%
==========================================
Files 26 26
Lines 3035 3104 +69
==========================================
+ Hits 1683 1747 +64
- Misses 1352 1357 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive support for detecting and handling fixture usage via pytestmark assignments in pytest tests. The implementation enables the language server to recognize fixtures used through pytestmark = pytest.mark.usefixtures(...) patterns at module and class level, and provides fixture completion suggestions when editing these constructs.
Changes:
- Added detection of fixture usage via
pytestmarkassignments (both plain and annotated) with support for nested structures (lists, tuples) - Enhanced completion context logic to provide fixture suggestions within
pytestmarkusefixtures calls - Added comprehensive test coverage for various pytestmark patterns and completion scenarios
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/fixtures/decorators.rs | Adds extract_usefixtures_from_expr function to recursively extract fixture names from expressions containing usefixtures calls |
| src/fixtures/analyzer.rs | Implements visit_pytestmark_assignment to detect and record pytestmark-based fixture usage for both plain and annotated assignments |
| src/fixtures/resolver.rs | Enhances check_decorator_context and adds cursor_inside_usefixtures_call to provide completion context for pytestmark usefixtures |
| tests/test_decorators.rs | Adds unit tests for extract_usefixtures_from_expr covering direct calls, lists, tuples, and empty cases |
| tests/test_fixtures.rs | Adds integration tests for pytestmark fixture detection and completion context across various patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request improves the detection and handling of
pytestmark = pytest.mark.usefixtures(...)(and related patterns) in the fixture analysis and completion logic. It ensures that fixtures used viapytestmarkassignments—whether as a direct call, in lists, tuples, or annotated assignments—are correctly recognized as used, and that fixture completions are offered when editing these constructs. The changes also include comprehensive tests for these scenarios.Key changes include:
Fixture Usage Detection Enhancements:
FixtureDatabaseto detect and record fixture usages viapytestmarkassignments, supporting both direct and annotated assignment forms (pytestmark = ...andpytestmark: T = ...), as well as nested structures like lists and tuples. [1] [2]extract_usefixtures_from_exprfunction indecorators.rsto recursively extract fixture names from any expression containingpytest.mark.usefixtures(...), including within lists and tuples.Completion Context Improvements:
pytest.mark.usefixtures(...)call within apytestmarkassignment, so fixture completions are suggested in these contexts. [1] [2] [3] [4]Testing:
pytestmarkassignment patterns intest_decorators.rs, ensuring robust parsing of direct calls, lists, tuples, and cases with nousefixtures.test_fixtures.rsto verify that fixture usages viapytestmark(including in classes and annotated assignments) are detected and that unused fixture detection works as expected.pytestmarkusefixturescalls, and not for unrelated marks.These updates make the fixture analysis and completion system much more robust and user-friendly for common pytest idioms involving
pytestmark.