fix(gazelle): Do not create invalid py_test rules in project generation mode#1809
Merged
aignas merged 4 commits intobazel-contrib:mainfrom Mar 21, 2024
Merged
Conversation
1141cc4 to
d53c19b
Compare
d53c19b to
3b6311f
Compare
aignas
approved these changes
Mar 21, 2024
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_testrule 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_testrule is created even when there is no test entrypoint file (__test__.py) nor any test file in the entire project. Additionally, test rules created onprojectorpackagegeneration mode will always setmain = "__test__.py", even when that file doesn't exist.This PR fixes it by only generating a
py_testrule 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__.pyfile. Note that, in the case where a__test__.pyfile doesn't exist, the generatedpy_testrule is likely invalid as-is due to the lack ofmain; this can be fixed by mapping to some otherpy_testimplementation, and I believe the new behavior makes more sense than pointingmainto a non-existing file.It may be useful to review per-commit (all tests pass on each commit):