rules_python
rules_python copied to clipboard
_test.py files being included in py_library rather than py_test
🐞 bug report
Affected Rule
bazel run //:gazelle
Is this a regression?
No
Description
The python gazelle tool does not create a py_test for all _test.py files. I think it requires that the test file prefix to be the same as the package. If the prefix is not the same, it adds the _test.py file to a py_library rule.
🔬 Minimal Reproduction
Just make a _test.py file whose prefix is not the same as the package it resides in.
+1
I think this PR is going to fix this: https://github.com/bazelbuild/rules_python/pull/723
Upon further inspection it does look like py_tests are created out of files beginning with test_ or ending with _test.py if and only if you also have a test target named __test__ OR have a __test__.py file in your project. See https://github.com/bazelbuild/rules_python/blob/ffcf0ecc54064e5776d24c3e150d3ddac86beaa0/gazelle/generate.go
That is what we are doing, but it this what we would expect? I wonder if we should support generating py_test declarations when we have foo_test.py. The documentation does not mention __test__.py either.
Chatting with @f0rmiga this is working as expected. And https://github.com/aspect-build/rules_py does have support for adding all _test.py files with a macro. I wonder if rules_python should support having a flag to pull in _test.py files. I am going to update the docs to add a bit of clarity
@f0rmiga can you give me a couple of sentences on what is supported? I know that __test__.py is supported, is foo_test.py supported?
If #999 is not sufficient, please reopen this ticket.