feat(gazelle): resolve pytest_plugins declarations as dependencies - #4207
Open
TrapsterDK wants to merge 5 commits into
Open
TrapsterDK wants to merge 5 commits into
TrapsterDK wants to merge 5 commits into
Conversation
TrapsterDK
marked this pull request as ready for review
October 5, 2026 11:37
TrapsterDK
requested review from
aignas,
dougthor42 and
rickeylev
as code owners
October 5, 2026 11:37
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Built-in plugin aliases such as pytester cause dependency-validation failures under default settings.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds Gazelle dependency discovery for static pytest_plugins declarations, reducing manual dependency annotations and addressing #4196.
Changes:
- Parses supported literal declarations using the existing dependency resolver.
- Adds parser and BUILD-generation regressions.
- Documents supported syntax and limitations.
| File | Description |
|---|---|
| news/4196.added.md | Announces plugin dependency support. |
| gazelle/python/testdata/pytest_plugins/WORKSPACE | Defines fixture workspace. |
| gazelle/python/testdata/pytest_plugins/test.yaml | Specifies successful generation. |
| gazelle/python/testdata/pytest_plugins/support/database.py | Exercises plugin prerequisites. |
| gazelle/python/testdata/pytest_plugins/support/BUILD.out | Records prerequisite dependencies. |
| gazelle/python/testdata/pytest_plugins/support/BUILD.in | Initializes support package. |
| gazelle/python/testdata/pytest_plugins/support/admin.py | Supplies prerequisite fixture. |
| gazelle/python/testdata/pytest_plugins/README.md | Explains regression scope. |
| gazelle/python/testdata/pytest_plugins/plugin_test.py | Exercises declarations and resolution controls. |
| gazelle/python/testdata/pytest_plugins/isolated_test.py | Checks sibling isolation. |
| gazelle/python/testdata/pytest_plugins/gazelle_python.yaml | Maps external dependencies. |
| gazelle/python/testdata/pytest_plugins/BUILD.out | Records expected test dependencies. |
| gazelle/python/testdata/pytest_plugins/BUILD.in | Configures resolution directives. |
| gazelle/python/testdata/pytest_plugins_conftest/WORKSPACE | Defines conftest fixture workspace. |
| gazelle/python/testdata/pytest_plugins_conftest/test.yaml | Specifies successful generation. |
| gazelle/python/testdata/pytest_plugins_conftest/README.md | Explains root-conftest coverage. |
| gazelle/python/testdata/pytest_plugins_conftest/gazelle_python.yaml | Maps pytest dependency. |
| gazelle/python/testdata/pytest_plugins_conftest/fixtures.py | Supplies reusable fixture. |
| gazelle/python/testdata/pytest_plugins_conftest/consumer_test.py | Consumes conftest-provided fixture. |
| gazelle/python/testdata/pytest_plugins_conftest/conftest.py | Declares root plugin. |
| gazelle/python/testdata/pytest_plugins_conftest/BUILD.out | Records transitive dependencies. |
| gazelle/python/testdata/pytest_plugins_conftest/BUILD.in | Enables per-file generation. |
| gazelle/python/file_parser.go | Extracts static plugin declarations. |
| gazelle/python/file_parser_test.go | Covers syntax, scope, and metadata. |
| gazelle/docs/installation_and_usage.md | Documents support and limitations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

AI written, human reviewed.
Summary
Pytest loads reusable fixture modules through
pytest_plugins, but Gazellecurrently discovers only ordinary imports. Users must therefore duplicate plugin
dependencies in BUILD files or
gazelle:include_depannotations.Treat static module-level
pytest_pluginsassignments as imports and reuse theexisting dependency resolver. Support literal strings, lists, tuples, annotated
and chained assignments, implicit string concatenation, and common Python string
escapes. Reuse buildtools' existing unquoting with narrow Python 3 normalization.
Match pytest's comma-separated single-string form and retain literal dependencies
when lists or tuples also contain dynamic entries.
Preserve dependency-ignore annotations, resolution directives, source locations,
and type-checking metadata. Exclude function/class-local declarations and document
unsupported dynamic expressions. Conditional declarations are conservatively
included, as with ordinary conditional imports.
Add parser edge-case tests and BUILD-generation regressions covering reusable
plugin prerequisites, a workspace-root conftest, external modules, duplicate dependencies,
resolution overrides, ignore behavior, and unrelated sibling test isolation.
Fixes #4196.
Verification
From
gazelle/:bazel test --config=fast-tests //...— all 87 test targets pass.gofmtcheck on the modified Go files — clean.git diff --check— clean.This changes dependency generation only; pytest's invocation-wide plugin
registration behavior is unchanged. Dynamic declarations and named Unicode
escapes remain unsupported and can use the existing explicit dependency
annotation.