You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please check if your PR fulfills the following requirements:
Tests for the changes have been added (for bug fixes / features)
Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
Bugfix
Feature (please, look at the "Scope of the project" section in the README.md file)
Code style update (formatting, local variables)
Refactoring (no functional changes, no api changes)
Build related changes
CI related changes
Documentation content changes
Other... Please describe:
What is the current behavior?
The Gazelle extension requires the existence of __test__.py or a target named __test__ to generate py_test targets. Otherwise, all _test.py and test_*.py will be included into py_library.
__test__.py is not part of official Python specification. In fact, it is rarely used in existing open source Python projects. A more common scenario is to have _test.py or test_*.py files, each with something like:
if __name__ == '__main__':
unittest.main()
This PR creates a py_test target per test Python file when neither __test__.py or a target named __test__ exists.
The reason will be displayed to describe this comment to others. Learn more.
I know at least a few repositories that this will be a breaking change. I've seen files using these patterns to contain test utilities and be reused by multiple tests. Ideally, those should be renamed to adhere to better practices. Having said that, we will need warning notes on the next release. cc @groodt@rickeylev
Since #999, gazelle can
generate multiple `py_test` rules in a single package (when it finds
multiple `*_test.py` or `test_*.py` files and no `__test__.py` file). In
this case, adding new test files to a package with pre-existing
`py_test` rules is not handled properly due to the `MatchAny` property
on the `py_test` kind - it will match the existing `py_test` rule and
edit it instead of adding a new test rule. This PR disables the matching
so that new `py_test` rules are properly generated.
…les (#2998)
Remove entry point file requirements when generating rules. Enable
python rule generation as long as there are .py source files under the
directory so all new packages will have python rules generated in the
package.
The extension used to require entrypoints for generation but:
- entry point for tests (i.e., `__test__.py` ) is no longer required
after #999 and
#2044
- entry point for binaries (i.e., `__main__.py` ) is no longer required
after #1584
The entry point for libraries (`__init__.py` ) shouldn't be required
either, especially for Python 3.3 and after when namespace packages are
supported.
---------
Co-authored-by: yushan <yushan@uber.com>
Co-authored-by: Douglas Thor <dougthor42@users.noreply.github.com>
amartani pushed a commit
to benchling/rules_python
that referenced
this pull request
Jul 8, 2025
…les (bazel-contrib#2998)
Remove entry point file requirements when generating rules. Enable
python rule generation as long as there are .py source files under the
directory so all new packages will have python rules generated in the
package.
The extension used to require entrypoints for generation but:
- entry point for tests (i.e., `__test__.py` ) is no longer required
after bazel-contrib#999 and
bazel-contrib#2044
- entry point for binaries (i.e., `__main__.py` ) is no longer required
after bazel-contrib#1584
The entry point for libraries (`__init__.py` ) shouldn't be required
either, especially for Python 3.3 and after when namespace packages are
supported.
---------
Co-authored-by: yushan <yushan@uber.com>
Co-authored-by: Douglas Thor <dougthor42@users.noreply.github.com>
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
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The Gazelle extension requires the existence of
__test__.pyor a target named__test__to generatepy_testtargets. Otherwise, all_test.pyandtest_*.pywill be included intopy_library.Issue Number: #714
What is the new behavior?
__test__.pyis not part of official Python specification. In fact, it is rarely used in existing open source Python projects. A more common scenario is to have_test.pyortest_*.pyfiles, each with something like:This PR creates a
py_testtarget per test Python file when neither__test__.pyor a target named__test__exists.Does this PR introduce a breaking change?
Other information