Hi all, bit of a dumb question, but how do I have ...
# general
a
Hi all, bit of a dumb question, but how do I have pants pick up tests within a folder? My current directory is like this and works fine:
Copy code
tests/
   - test_a.py
   - test_b.py
   - BUILD
I want to have a structure like this:
Copy code
tests/
   - test_a.py
   - test_b.py
   - BUILD
   - extra/
      - test_c.py
      - test_d.py
What do I need to do to have my BUILD pick up the tests in that directory as well?
c
a
python_tests
target in you BUILD file will cause all test-like files to be picked up.
./pants tailor ::
should add one
But that's only in one directory, by default. You can add another BUILD file in "//tests/extra" (tailor will generate this), or you can add a target in the "//tests/BUILD" file that points to the "//tests/extra" folder. You can also modify the original
python_tests
target to include both the "//tests/" and "//tests/extra" directories. I usually let tailor do it, because it's done for me and if I need to modify the BUILD file it's right there.
w
Semi-related: https://pantsbuild.slack.com/archives/C046T6T9U/p1666526308457769 As Daniel was saying,
./pants tailor
will basically put a
BUILD
file in each of your directories with the
python_sources
or
python_tests
It's referred to as 111 in the Slacks (though I can never remember why), alluding to 1 BUILD file per directory. Otherwise, you'll need to glob the sources in your BUILD.
By glob, I'm referring to this here: https://www.pantsbuild.org/docs/reference-python_tests#codesourcescode
sources=['**/test_*.py', '**/*_test.py', '**/tests.py']
(or whatever)
c
111 is one dir, one build file, one target per file iirc.
👍 1
a
The power of
./pants tailor
… thanks guys!
w
one target per file
@curved-television-6568 That can't be right
c
@wide-midnight-78598 there’s target generators to get you the last mile ;)
😃 1
h
I coined 111 back in the day at Foursquare, and I can’t remember what the third “1” is…
🙃 2
w
1 Benjy?