Skip to content

fix(gazelle): merge pytest conftest annotations deterministically - #4167

Open
amartani wants to merge 2 commits into
bazel-contrib:mainfrom
benchling:martani/fix-gazelle-pytest-conftest-annotation
Open

amartani wants to merge 2 commits into
bazel-contrib:mainfrom
benchling:martani/fix-gazelle-pytest-conftest-annotation

Conversation

@amartani

@amartani amartani commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

When a py_test had multiple srcs, Gazelle kept only the last
include_pytest_conftest annotation parsed from those sources.
Because sources are parsed concurrently, an omitted annotation could
overwrite an explicit value, such as false. Explicit true and
false values could also silently overwrite each other.

Aggregate explicitly set values across all sources instead. Preserve an
explicit value when other sources omit the annotation, and reject
conflicting explicit values so generation remains deterministic.
Add unit and integration coverage and document the behavior.

Related to #3076.

Concurrent parsing let an unset value overwrite an explicit annotation.

This made test generation depend on parser completion order.

Track explicit true and false values across all source files.

Preserve an agreed value and reject conflicts.
The news fragment did not clearly describe the user-visible outcome.

Clarify when annotations are kept and when Gazelle reports an error.

Also wrap the stderr fixture and use API cross-references.
@amartani
amartani marked this pull request as ready for review September 19, 2026 04:03
Copilot AI lite review requested due to automatic review settings September 19, 2026 04:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Restrict annotation conflict aggregation to py_test paths so non-test targets do not fail on irrelevant conflicting values.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes nondeterministic merging of include_pytest_conftest annotations across multiple Python sources.

Changes:

  • Preserve explicit values and reject conflicting values.
  • Add unit and integration coverage.
  • Document the behavior and add a release note.
File Summary
news/​gazelle-pytest-conftest.fixed.md Adds a release note.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​WORKSPACE Defines the integration fixture workspace.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​true_test.py Provides the explicit true annotation case.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​test.yaml Configures the integration fixture.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​README.md Documents the conflict fixture.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​false_test.py Provides the explicit false annotation case.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​conftest.py Supports the pytest fixture.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​BUILD.out Expected generated BUILD output.
gazelle/​python/​testdata/​annotation_include_pytest_conftest_conflict/​BUILD.in Input BUILD fixture.
gazelle/​python/​parser.go Aggregates annotation values and detects conflicts. Moderate issue: this also affects non-test targets and can reject conflicting annotations that should have no effect there.
gazelle/​python/​parser_test.go Adds parser coverage.
gazelle/​python/​BUILD.bazel Registers test sources and dependencies.
gazelle/​docs/​annotations.md Documents multi-source annotation behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread gazelle/python/parser.go
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.

2 participants