https://pantsbuild.org/ logo
#general
Title
# general
a

ambitious-xylophone-5772

10/26/2022, 11:27 PM
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

careful-address-89803

10/26/2022, 11:40 PM
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

wide-midnight-78598

10/26/2022, 11:47 PM
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

curved-television-6568

10/27/2022, 12:08 AM
111 is one dir, one build file, one target per file iirc.
👍 1
a

ambitious-xylophone-5772

10/27/2022, 12:22 AM
The power of
./pants tailor
… thanks guys!
w

wide-midnight-78598

10/27/2022, 12:27 AM
one target per file
@curved-television-6568 That can't be right
c

curved-television-6568

10/27/2022, 12:30 AM
@wide-midnight-78598 there’s target generators to get you the last mile ;)
😃 1
h

happy-kitchen-89482

10/27/2022, 12:58 AM
I coined 111 back in the day at Foursquare, and I can’t remember what the third “1” is…
🙃 2
w

wide-midnight-78598

10/27/2022, 1:22 AM
1 Benjy?
3 Views