-
Notifications
You must be signed in to change notification settings - Fork 543
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
Gazelle considers both test_*.py
and *_test.py
files to be py_test
targets.
#1816
Comments
This can be solved by adding a directive (I seem to love directives...). Something like:
I imagine the directive supporting a comma-separated list of
If this sounds like a good solution LMK and I'll be happy to take a stab at it. |
It occurred to me today as well and I literally have |
Yes, though it seems like it's going out of style in favor of
|
The suggested implementation sounds good to me. I think the default behaviour even had a few tests to ensure that people can create libraries with 'test' in the file. But that might have changed at some point. |
Add the `python_test_file_pattern` directive. This directive allows users to configure what python files get mapped to the `py_test` rule. The default behavior is unchanged: both `test_*` and `*_test.py` files generate `py_test` targets if the directive is unset. The directive supports multiple glob patterns, separated by a comma. Note: The original code used, effectively, `test_*` for one of the patterns. This code uses `test_*.py` instead. These are equivalent because of the `.py` extension check prior to pattern matching. Fixes #1816.
🐞 bug report
Affected Rule
Is this a regression?
Nope! Just unexpected behavior.
Description
A typical python project will use only one of
*_test.py
ortest_*.py
to name test files.However, gazelle will make
py_test
targets for both types:rules_python/gazelle/python/generate.go
Line 116 in e86252f
rules_python/gazelle/python/generate.go
Line 198 in e86252f
This can lead to unexpected behavior:
Example 1: unit test utilities
Assume that a project uses
*_test.py
for 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.py
file because that does not get collected by the pytest test runner.gazelle
will incorrectly (at least according to the user) make: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
orfoo_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_test
targets for such instead ofpy_library
targets.🔬 Minimal Reproduction
test_foo.py
foo_test.py
gazelle
py_test
targets.🔥 Exception or Error
N/A
🌍 Your Environment
Operating System:
Output of
bazel version
:Rules_python version:
Anything else relevant?
Don't think so.
The text was updated successfully, but these errors were encountered: