Pants defaults to assuming tests could look like `...
# general
h
Pants defaults to assuming tests could look like
test_*.py
or
*_test.py
. We exclusively use the latter and the former is always a
python_source
for us. Is there a way to globally teach Pants this about our repo? I think
__defaults__
gets us partially there, but I think
pants tailor
still looks at the builtin behavior when helping create targets.
Here's a quick demo of what I mean Make a file that is normally a test but is a source in this case (
test_something.py
)
Copy code
# Here is my super important module

def main() -> None:
  print('Hello world')
Add a
BUILD
file that instructs this to not be owned a
python_test
target
Copy code
__defaults__({python_tests: {"sources": ["*_test.py"]}})
Run
pants tailor ::
and see that it wants to make a
python_tests
target in the
BUILD
file
Copy code
$ pants tailor ::
Updated path/to/BUILD.pants:
  - Add python_tests target tests
See that any goal (
list
is easy enough) complains about not finding sources for the newly added target
Copy code
$ pants list path/to/test_something.py 
18:35:47.73 [ERROR] 1 Exception encountered:

Engine traceback:
  in `list` goal
  in Find targets from input specs

IntrinsicError: Unmatched glob from path/to:tests's `sources` field: "path/to/*_test.py"

Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.16/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
b
What happens if you add a
__default__
for
python_sources
too?
tailor
won't add new targets for files that are owned, and that config makes it sound like
test_something.py
isn't associated with any target?
h
That default is a lot more wild to update but I can give it a try
Which is a shame...