Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 21, 2024

Conversation

amartani
Copy link
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
@aignas aignas added this pull request to the merge queue Mar 21, 2024
Merged via the queue into bazelbuild:main with commit d5945ed Mar 21, 2024
4 checks passed
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