feat!: Following generation mode when generating test targets #2044
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.
When
python_generation_mode
isproject
orfile
, the generatedpy_test
targets are consistent withpy_library
. However, whenpython_generation_mode
ispackage
, it becomes inconsistent: it requires either__test__
target or__test__.py
file to generatepy_test
in package mode, otherwise it will fall back to file mode.This PR relaxes this requirement with a new directive
gazelle:python_generation_mode_per_package_require_test_entry_point
. Whent it's set to false, Gazelle and generates onepy_test
target per package in package mode even without entry points.This allows people to use
gazelle:map_kind
to mappy_test
to a macro that sets a default test runner, such as rules_python_pytest or pytest-bazel, and generate one test target per package. The behavior whengazelle:python_generation_mode
is "file" or "project" remains the same.This fixes #1972 for supporting pytest from Gazelle. With this approach, people can define a thin macro like this to use py_pytest_main:
BREAKING CHANGES:
Without
gazelle:map_kind
or__test__
target or__test__.py
, the package mode will now generatepy_test
withoutmain
attribute, which may not be runnable. However, this is already an issue with "python_generation_mode:project" before this PR.The default value of
gazelle:python_generation_mode_per_package_require_test_entry_point
is true to preserve the current behavior. We will flip that default value in the future.