Skip to content

feat: support pytestmark = pytest.mark.usefixtures for fixture usage#91

Merged
bellini666 merged 1 commit intobellini666:masterfrom
benediktziegler:detect-usefixtures-in-nested-stmts
Feb 20, 2026
Merged

feat: support pytestmark = pytest.mark.usefixtures for fixture usage#91
bellini666 merged 1 commit intobellini666:masterfrom
benediktziegler:detect-usefixtures-in-nested-stmts

Conversation

@benediktziegler
Copy link
Copy Markdown
Contributor

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 via pytestmark assignments—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:

  • Added logic in FixtureDatabase to detect and record fixture usages via pytestmark assignments, supporting both direct and annotated assignment forms (pytestmark = ... and pytestmark: T = ...), as well as nested structures like lists and tuples. [1] [2]
  • Implemented the extract_usefixtures_from_expr function in decorators.rs to recursively extract fixture names from any expression containing pytest.mark.usefixtures(...), including within lists and tuples.

Completion Context Improvements:

  • Enhanced the completion context logic to recognize when the cursor is inside a pytest.mark.usefixtures(...) call within a pytestmark assignment, so fixture completions are suggested in these contexts. [1] [2] [3] [4]

Testing:

  • Added extensive tests for extracting fixture names from various pytestmark assignment patterns in test_decorators.rs, ensuring robust parsing of direct calls, lists, tuples, and cases with no usefixtures.
  • Added integration tests in test_fixtures.rs to verify that fixture usages via pytestmark (including in classes and annotated assignments) are detected and that unused fixture detection works as expected.
  • Added tests to verify that fixture completion suggestions are correctly provided when editing inside pytestmark usefixtures calls, 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.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 88.75000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.28%. Comparing base (b971dc4) to head (53a08e6).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/fixtures/resolver.rs 81.25% 9 Missing ⚠️
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.
📢 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 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 pytestmark assignments (both plain and annotated) with support for nested structures (lists, tuples)
  • Enhanced completion context logic to provide fixture suggestions within pytestmark usefixtures 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.

@bellini666 bellini666 merged commit 9ebacf6 into bellini666:master Feb 20, 2026
18 checks passed
@benediktziegler benediktziegler deleted the detect-usefixtures-in-nested-stmts branch February 20, 2026 14:01
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.

3 participants