🐞 bug report
Affected Rule
Is this a regression?
Nope! Just unexpected behavior.
Description
A typical python project will use only one of *_test.py or test_*.py to name test files.
However, gazelle will make py_test targets for both types:
https://github.com/bazelbuild/rules_python/blob/e86252ffd6d1a1bf32ae99933acc5ab49b78ec1e/gazelle/python/generate.go#L116
https://github.com/bazelbuild/rules_python/blob/e86252ffd6d1a1bf32ae99933acc5ab49b78ec1e/gazelle/python/generate.go#L198
This can lead to unexpected behavior:
Example 1: unit test utilities
Assume that a project uses *_test.py for unit/integration tests. Using pytest, the config would be:
[tool.pytest.ini_options]
python_files = ["*_test.py"]
Also assume that there needs to be some utilities related to testing. A typical solution would be to make a test_utils.py file because that does not get collected by the pytest test runner.
gazelle will incorrectly (at least according to the user) make:
py_test(
name = "test_utils",
srcs = ["test_utils.py"],
)
The user expects a py_library instead.
Example 2: Non-code tests, such as electrical or physical testing
Code that deals with electrical or physical testing (voltage, current, vibration, pressure, etc) is typically called test_foo or foo_test. For example, code that determines the breakdown voltage of a part might be called test_breakdown_voltage.py. Code might also need to create collections or suites of non-code tests, and would live in test_suites.py.
Again, according to the user, gazelle will incorrectly make py_test targets for such instead of py_library targets.
🔬 Minimal Reproduction
- Make
test_foo.py
- Make
foo_test.py
- Run
gazelle
- See that both were generated as
py_test targets.
🔥 Exception or Error
N/A
🌍 Your Environment
Operating System:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux rodete
Release: n/a
Codename: rodete
Output of bazel version:
$ bazel version
Starting local Bazel server and connecting to it...
Build label: 7.1.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Mar 11 17:55:31 2024 (1710179731)
Build timestamp: 1710179731
Build timestamp as int: 1710179731
Rules_python version:
0.31.0 @ bdb2aa2e5c0ca435918037aa3568c0b0c4c9c1ab
Anything else relevant?
Don't think so.
🐞 bug report
Affected Rule
Is this a regression?
Nope! Just unexpected behavior.
Description
A typical python project will use only one of
*_test.pyortest_*.pyto name test files.However, gazelle will make
py_testtargets for both types:https://github.com/bazelbuild/rules_python/blob/e86252ffd6d1a1bf32ae99933acc5ab49b78ec1e/gazelle/python/generate.go#L116
https://github.com/bazelbuild/rules_python/blob/e86252ffd6d1a1bf32ae99933acc5ab49b78ec1e/gazelle/python/generate.go#L198
This can lead to unexpected behavior:
Example 1: unit test utilities
Assume that a project uses
*_test.pyfor unit/integration tests. Usingpytest, the config would be:Also assume that there needs to be some utilities related to testing. A typical solution would be to make a
test_utils.pyfile because that does not get collected by the pytest test runner.gazellewill incorrectly (at least according to the user) make:The user expects a
py_libraryinstead.Example 2: Non-code tests, such as electrical or physical testing
Code that deals with electrical or physical testing (voltage, current, vibration, pressure, etc) is typically called
test_fooorfoo_test. For example, code that determines the breakdown voltage of a part might be calledtest_breakdown_voltage.py. Code might also need to create collections or suites of non-code tests, and would live intest_suites.py.Again, according to the user, gazelle will incorrectly make
py_testtargets for such instead ofpy_librarytargets.🔬 Minimal Reproduction
test_foo.pyfoo_test.pygazellepy_testtargets.🔥 Exception or Error
N/A
🌍 Your Environment
Operating System:
Output of
bazel version:Rules_python version:
Anything else relevant?
Don't think so.