Skip to content

feat(gazelle): resolve pytest_plugins declarations as dependencies - #4207

Draft
TrapsterDK wants to merge 4 commits into
bazel-contrib:mainfrom
TrapsterDK:feat/gazelle-pytest-plugins
Draft

TrapsterDK wants to merge 4 commits into
bazel-contrib:mainfrom
TrapsterDK:feat/gazelle-pytest-plugins

Conversation

@TrapsterDK

@TrapsterDK TrapsterDK commented Oct 1, 2026 •

Copy link
Copy Markdown

AI written, human reviewed.

Summary

Pytest loads reusable fixture modules through pytest_plugins, but Gazelle
currently discovers only ordinary imports. Users must therefore duplicate plugin
dependencies in BUILD files or gazelle:include_dep annotations.

Treat static module-level pytest_plugins assignments as imports and reuse the
existing 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.
  • gofmt check 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.

This branch has not been deployed

No deployments
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.

feat: Support parsing pytest_plugins as a form of import.

1 participant