Skip to content

fix(gazelle): Do not create invalid py_test rules in project generation mode#1809

Merged
aignas merged 4 commits intobazel-contrib:mainfrom
amartani:amartani/gazelle-project-generation
Mar 21, 2024
Merged

fix(gazelle): Do not create invalid py_test rules in project generation mode#1809
aignas merged 4 commits intobazel-contrib:mainfrom
amartani:amartani/gazelle-project-generation

Conversation

@amartani
Copy link
Copy Markdown
Contributor

@amartani amartani commented Mar 16, 2024

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.

@amartani amartani force-pushed the amartani/gazelle-project-generation branch 2 times, most recently from 1141cc4 to d53c19b Compare March 20, 2024 21:52
@amartani amartani force-pushed the amartani/gazelle-project-generation branch from d53c19b to 3b6311f Compare March 20, 2024 22:17
@amartani amartani marked this pull request as ready for review March 20, 2024 22:30
@amartani amartani requested a review from f0rmiga as a code owner March 20, 2024 22:30
@amartani amartani requested a review from rickeylev as a code owner March 20, 2024 23:25
@aignas aignas added this pull request to the merge queue Mar 21, 2024
Merged via the queue into bazel-contrib:main with commit d5945ed Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants