fix(gazelle): generate a single py_test for coarse_grained setups#1538
Merged
rickeylev merged 1 commit intobazel-contrib:mainfrom Nov 6, 2023
Merged
Conversation
With a recent change to generate a single test target per python file we introduced a regression for projects using `# gazelle:python_generation_mode project` configuration directive if there are multiple files with the same filenames but under different directories within the source tree. This PR fixes the behaviour so that we just generate a single target containing all test files as there is no sure way to denormalize the paths so that they never clash. Fixes bazel-contrib#1442.
rickeylev
approved these changes
Nov 6, 2023
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 21, 2024
…tion mode (#1809) Since #1538, when using `gazelle:python_generation_mode project`, a `py_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 a `py_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 on `project` or `package` generation mode will always set `main = "__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 with `test_` or suffixed with `_test.py`. It also changes the generated test rule to only add `main = "__test__.py"` if there is an actual `__test__.py` file. Note that, in the case where a `__test__.py` file doesn't exist, the generated `py_test` rule is likely invalid as-is due to the lack of `main`; this can be fixed by mapping to some other `py_test` implementation, and I believe the new behavior makes more sense than pointing `main` to a non-existing file. It may be useful to review per-commit (all tests pass on each commit): - First commit reproduces the issue; - Second commit fixes the issue and the corresponding tests; - Third commit adds additional test cases.
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.
With a recent change to generate a single test target per python file
we introduced a regression for projects using
# gazelle:python_generation_mode projectconfiguration directiveif there are multiple files with the same filenames but under different
directories within the source tree. This PR fixes the behaviour so that
we just generate a single target containing all test files as there is
no sure way to denormalize the paths so that they never clash.
Fixes #1442.