rules_python
rules_python copied to clipboard
`python_generation_mode project` generating unnecesary/empty `py_test`
🐞 bug report
Affected Rule
Gazelle with # gazelle:python_generation_mode project
Is this a regression?
Yes, the previous version in which this bug was not present was: 0.26.0
Description
A clear and concise description of the problem...Since 0.27.0, having # gazelle:python_generation_mode project Gazelle directive is generating an empty py_test despite __test__.py not existing.
I believe it is related this change: https://github.com/bazelbuild/rules_python/pull/1538
For example,
py_test(
name = "folder_test",
imports = ["../.."],
main = "__test__.py",
)
There isn't even a srcs parameter, so it doesn't even work.
🔬 Minimal Reproduction
- A directory with Python files and a
BUILD.bazel- No test files
- No
__test__.py
- Add
# gazelle:python_generation_mode projectdirective - Run Python Gazelle on that directory
🌍 Your Environment
- Replicated on both MacOS and Ubuntu Linux
We are currently working around this with this patch:
--- python/generate.go
+++ python/generate.go
@@ -375,7 +375,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
addModuleDependencies(deps).
generateImportsAttribute()
}
- if (hasPyTestEntryPointFile || hasPyTestEntryPointTarget || cfg.CoarseGrainedGeneration()) && !cfg.PerFileGeneration() {
+ if (hasPyTestEntryPointFile || hasPyTestEntryPointTarget) && !cfg.PerFileGeneration() {
// Create one py_test target per package
if hasPyTestEntryPointFile {
// Only add the pyTestEntrypointFilename to the pyTestFilenames if
Would be great to have a better fix though.
Fixed by #1809