echoing-farmer-15630
03/24/2021, 8:33 PM.pants test
a directory full of, well, tests. The BUILD
has sources=["***/**.py"
and includes all the test files. Except that there are a couple of files in there without actual tests; they're imported by the test files.
Running the test target works, but those files print === no tests ran in 0.01s ===
and are listed by pants as "failed", ie
❯ ./pants test --force some/file/without/tests.py
/home/vputz/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0.dev2+gitd46197d0_py38
15:29:46.22 [INFO] initializing scheduler...
15:29:46.55 [INFO] scheduler initialized.
𐄂 some/file/without/tests.py:../../tests failed.
within an appropriate venv,
❯ pytest some/file/without/tests.py
======================================================== test session starts =========================================================
platform linux -- Python 3.9.0+, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /root/dir/wotever
plugins: some-plugins
collected 0 items
======================================================= no tests ran in 0.01s ========================================================
How can I avoid a "failed" with a "no tests ran" result--or skip the test running on files without tests (while still including them for dependencies)? If I .pants test the_actual_test_target
it runs all the tests but lists the files without tests as "failed" (and thus the test target fails). If I pytest
the directory representing the test target it doesn't even pick out the files without tests.witty-crayon-22786
03/24/2021, 8:35 PMThedo you have separate targets for the tests and the libraries? i’m guessing not if you’re using that glob…hasBUILD
and includes all the test files. Except that there are a couple of files in there without actual tests; they’re imported by the test files.sources=["***/**.py"
witty-crayon-22786
03/24/2021, 8:40 PM./pants tailor
? https://www.pantsbuild.org/docs/create-initial-build-fileswitty-crayon-22786
03/24/2021, 8:41 PMechoing-farmer-15630
03/24/2021, 8:42 PM./pants tailor
. I will say that I briefly tried putting the two "tools" files in the dependencies
field and then changing the sources
to only have the test sources, but then it complained that there wasn't a BUILD file down in there.
Got to run for today likely, but I'll try tailor
and see what it does.witty-crayon-22786
03/24/2021, 8:42 PMtailor
, and seeing what it does.echoing-farmer-15630
03/24/2021, 8:46 PMpython_library
target with name='test_tools'
and then including :test_tools
as a dependency in the python_tests
target seems to have done the trick for now.
Not quite how I anticipated that working to be honest, and it could still bite you I think if you marked all tests in a file as skipped, but I don't have time to test for now. I'll still check out tailor
for fun tomorrow.witty-crayon-22786
03/24/2021, 8:46 PMwitty-crayon-22786
03/24/2021, 8:46 PMhundreds-father-404
03/24/2021, 10:09 PMhappy-kitchen-89482
03/25/2021, 3:23 PM:test_tools
dependency should be inferrable, assuming you import from the test tools in the tests, so you could try leaving off that explict dependency (but keeping the test_tools
target itself around).happy-kitchen-89482
03/25/2021, 3:25 PMtailor
will assume that anything named tests.py
, test_*.py
or *_test.py
is a test, so if your tools file is literally named test_tools.py
it will miscategorize it as a test. So you may want to rename or to manually override the targets generated by tailor
in this case.