rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

_test.py files being included in py_library rather than py_test

Open domenic-donato opened this issue 3 years ago • 3 comments

🐞 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.

domenic-donato avatar May 25 '22 21:05 domenic-donato

+1

AugustKarlstedt avatar Jun 09 '22 18:06 AugustKarlstedt

I think this PR is going to fix this: https://github.com/bazelbuild/rules_python/pull/723

domenic-donato avatar Jun 09 '22 18:06 domenic-donato

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

AugustKarlstedt avatar Jun 13 '22 01:06 AugustKarlstedt

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.

chrislovecnm avatar Dec 06 '22 20:12 chrislovecnm

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

chrislovecnm avatar Dec 06 '22 21:12 chrislovecnm

@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?

chrislovecnm avatar Dec 19 '22 16:12 chrislovecnm

If #999 is not sufficient, please reopen this ticket.

aignas avatar Nov 05 '23 13:11 aignas