Running `pants test path/to/test/my_test.py` which...
# general
b
Running
pants test path/to/test/my_test.py
which depends on a directory of data files. These data files are in the same directory, so I suppose these become a
target
. I think I can add these files like so in the BUILD file that lives inside the
test
directory:
Copy code
python_tests(
    name="tests",
    dependencies=[":mydata"]
)

python_tests(
    name="tests0",

files(
    name="mydata",
    sources=["test-data/*"]
)
So far so good? ๐Ÿงต Edit: The issue was that there were two
python_tests
targets. Not sure how this happened. Maybe a
pants tailor ::
coupled with an overzealous read of the docs. I'm new to Pants. ๐Ÿ˜
So when calling
pants test path/to/test/my_test.py
I get a bunch of failed tests with
FileNotFoundError
. Puzzling. I then try to run with the debug flag, and set a breakpoint.
Copy code
pants test --debug path/to/test/my_test.py
and when I drop into the debugger at a breakpoint, I can use
os.listdir
and inspect some files in the sandbox. The files are there, as expected... So I continue. Lots of green tests.
Then, it appears that tests run again. But this time, the files are not present. Tests fail.
Overall, this appears as a failed test. Any hints on what might be going on?
e
How do your tests read the files? the CWD of the test process should be the sandbox dir and so the path your tests use would need to be "tests/test-data/*" from what you described.
The debugger may be adding in the original sources outside the sandbox back in the build root; so don't be fooled by debugger - I'd set that aside for the moment and use prints.
b
I'll try that out. Btw, would this layout be the culprit?
Copy code
.
โ””โ”€โ”€ Root
    โ””โ”€โ”€ myproject
        โ”œโ”€โ”€ BUILD
        โ”œโ”€โ”€ pyproject.toml
        โ”œโ”€โ”€ requirements.txt
        โ”œโ”€โ”€ src
        โ”‚   โ””โ”€โ”€ mymodule
        โ”‚       โ”œโ”€โ”€ BUILD
        โ”‚       โ”œโ”€โ”€ __init__.py
        โ”‚       โ””โ”€โ”€ version.py
        โ””โ”€โ”€ test
            โ”œโ”€โ”€ BUILD
            โ”œโ”€โ”€ test-data
            โ”‚   โ”œโ”€โ”€ 1573519488933.json
            โ”‚   โ”œโ”€โ”€ 1573519493613.json
            โ”‚   โ””โ”€โ”€ 1573519498213.json
            โ””โ”€โ”€ test_mymodule.py
The BUILD file where I call out the test data is Root/myproject/test/BUILD.
Oh geez... I see the issue now.
That build file has two
python_tests
targets.
PEBKAC
Thanks.