Skip to content

feat(gazelle): Directive controlling pytest ancestor dependencies#3596

Merged
dougthor42 merged 10 commits intobazel-contrib:mainfrom
dougthor42:u/dthor/gazelle-disable-conftest-gh3595
Feb 16, 2026
Merged

feat(gazelle): Directive controlling pytest ancestor dependencies#3596
dougthor42 merged 10 commits intobazel-contrib:mainfrom
dougthor42:u/dthor/gazelle-disable-conftest-gh3595

Conversation

@dougthor42
Copy link
Collaborator

Fixes #3595.

Add a new directive python_include_ancestor_conftest, defaulting to true, that configures whether or not ancestor conftest targets are added to a py_test target's dependencies.

@dougthor42 dougthor42 added type: feature request gazelle Gazelle plugin related issues labels Feb 14, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dougthor42, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new configuration option for Gazelle's Python extension, allowing users to explicitly control the inclusion of ancestor conftest.py files in py_test target dependencies. This addresses a previous issue where ancestor conftest files were not automatically added, and provides flexibility for users who may not desire this default behavior, ensuring better control over test dependency resolution.

Highlights

  • New Directive Introduced: A new Gazelle directive, python_include_ancestor_conftest, has been added to control whether ancestor conftest.py targets are automatically included as dependencies for py_test targets.
  • Configurable Behavior: This directive defaults to true, restoring the behavior of including all ancestor conftest.py files. Users can set it to false to revert to the pre-1.9.0 behavior where only sibling conftest targets are included.
  • Documentation and Testing: Comprehensive documentation for the new directive has been added, including examples. A new test suite has also been introduced to verify its functionality and inheritance behavior across different directory levels.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • gazelle/docs/annotations.md
    • Added an anchor for the include_pytest_conftest annotation.
  • gazelle/docs/directives.md
    • Added documentation for the new python_include_ancestor_conftest directive.
    • Included examples demonstrating the directive's behavior.
  • gazelle/python/configure.go
    • Registered python_include_ancestor_conftest in KnownDirectives.
    • Implemented parsing logic for the python_include_ancestor_conftest directive.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/BUILD.out
    • Added BUILD.out for the root conftest.py test case.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/README.md
    • Added a README explaining the test case for the new directive.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/BUILD.out
    • Added BUILD.out for the one/ subdirectory test case.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/BUILD.in
    • Added BUILD.in to test setting the directive to false.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/BUILD.out
    • Added BUILD.out for the one/two/ subdirectory test case with the directive set to false.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/three/BUILD.in
    • Added BUILD.in to test setting the directive back to true.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/three/BUILD.out
    • Added BUILD.out for the one/two/three/ subdirectory test case with the directive set to true.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/test.yaml
    • Added test.yaml for the new directive's test suite.
  • gazelle/pythonconfig/pythonconfig.go
    • Defined PythonIncludeAncestorConftest constant.
    • Added includeAncestorConftest field to Config struct.
    • Initialized includeAncestorConftest to true by default.
    • Implemented SetIncludeAncestorConftest and IncludeAncestorConftest methods.
    • Ensured the new field is copied in NewChild.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new Gazelle directive, python_include_ancestor_conftest, which allows users to control whether ancestor conftest.py targets are automatically added as dependencies to py_test targets. The directive is correctly registered, documented, and integrated into the configuration parsing logic. However, the actual implementation that uses this configuration during rule generation appears to be missing from gazelle/python/generate.go. Without this logic, the directive will not function as intended. Additionally, there are minor typos in the documentation and test data.

@dougthor42 dougthor42 changed the title feat(gazelle): Directive controlling pytest ancestor depdencies feat(gazelle): Directive controlling pytest ancestor dependencies Feb 15, 2026
@dougthor42 dougthor42 marked this pull request as ready for review February 15, 2026 22:55
+ The final level, `one/two/three`, sets the directive back to True and thus
the `py_test` target includes a total of 4 `conftest` targets.
+ The `one/two/three/no_conftest` directory does not contain a `conftest.py`
file and thus asserts that the code includes _only_ ancestor `conftest`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Man, I really like the phrase "and thus" ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had gemini provide some synonym phrases.

// We traverse up the tree to find conftest files and we start in
// the current package. Thus if we find one in the current package
// and do not want ancestors, we break early.
if !includeAncestorConftest {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

N.B.: I opted to keep this separate from the next if to make things more readable. LMK if anyone thinks otherwise:

if pkg == "" or !includeAncestorConftest {
	break
}

@dougthor42 dougthor42 enabled auto-merge February 16, 2026 06:43
@dougthor42 dougthor42 added this pull request to the merge queue Feb 16, 2026
Merged via the queue into bazel-contrib:main with commit c9783c8 Feb 16, 2026
4 checks passed
@dougthor42 dougthor42 deleted the u/dthor/gazelle-disable-conftest-gh3595 branch February 16, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gazelle Gazelle plugin related issues type: feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Directive to disable ancestor conftest.py deps

2 participants