Skip to content

Commit 8afbe99

Browse files
authored
fix(gazelle): generate a single py_test for coarse_grained setups (#1538)
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 #1442.
1 parent 3eebda1 commit 8afbe99

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Breaking changes:
7575
* (py_wheel) Produce deterministic wheel files and make `RECORD` file entries
7676
follow the order of files written to the `.whl` archive.
7777

78+
* (gazelle) Generate a single `py_test` target when `gazelle:python_generation_mode project`
79+
is used.
80+
7881
### Added
7982

8083
* (bzlmod) Added `.whl` patching support via `patches` and `patch_strip`

gazelle/python/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
371371
addModuleDependencies(deps).
372372
generateImportsAttribute()
373373
}
374-
if hasPyTestEntryPointFile || hasPyTestEntryPointTarget {
374+
if hasPyTestEntryPointFile || hasPyTestEntryPointTarget || cfg.CoarseGrainedGeneration() {
375375
if hasPyTestEntryPointFile {
376376
// Only add the pyTestEntrypointFilename to the pyTestFilenames if
377377
// the file exists on disk.

gazelle/python/testdata/monorepo/coarse_grained/BUILD.out

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@rules_python//python:defs.bzl", "py_library")
1+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
22

33
# gazelle:python_extension enabled
44
# gazelle:python_root
@@ -18,3 +18,12 @@ py_library(
1818
visibility = ["//:__subpackages__"],
1919
deps = ["@root_pip_deps//rootboto3"],
2020
)
21+
22+
py_test(
23+
name = "coarse_grained_test",
24+
srcs = [
25+
"bar/bar_test.py",
26+
"foo/bar/bar_test.py",
27+
],
28+
main = "__test__.py",
29+
)

gazelle/python/testdata/monorepo/coarse_grained/bar/bar_test.py

Whitespace-only changes.

gazelle/python/testdata/monorepo/coarse_grained/foo/bar/bar_test.py

Whitespace-only changes.

0 commit comments

Comments
 (0)