fix(gazelle): Do not create invalid py_test rules in project
generation mode
#1809
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.
Since #1538, when using
gazelle:python_generation_mode project
, apy_test
rule is created even when there are no test files in the project. fb673ee (first commit on the PR branch) reproduces this issue - it shows that apy_test
rule is created even when there is no test entrypoint file (__test__.py
) nor any test file in the entire project. Additionally, test rules created onproject
orpackage
generation mode will always setmain = "__test__.py"
, even when that file doesn't exist.This PR fixes it by only generating a
py_test
rule if it can find some test file - either an explicit__test__.py
, or any other file prefixed withtest_
or suffixed with_test.py
. It also changes the generated test rule to only addmain = "__test__.py"
if there is an actual__test__.py
file. Note that, in the case where a__test__.py
file doesn't exist, the generatedpy_test
rule is likely invalid as-is due to the lack ofmain
; this can be fixed by mapping to some otherpy_test
implementation, and I believe the new behavior makes more sense than pointingmain
to a non-existing file.It may be useful to review per-commit (all tests pass on each commit):