hundreds-father-404
08/12/2020, 11:19 PMconftest.py
. We end up generating a python_tests()
target for the conftest.py
file, then try running ./pants test conftest.py
, which causes Pytest to fail because there are no tests inside.
This is an issue with conftest.py
, but also any util file in a python_tests()
target.
Some possible solutions:
1. Stop having conftest.py
belong to python_tests()
and have it belong to python_library()
. python_tests()
should only have files with actual tests in them. This is conceptually pure, but also not very ergonomic, especially if your tests live in their own folders and you only had python_tests()
targets before.
2. Special case pytest_runner.py
to no-op if the file name is conftest.py
. But this would not catch if you had other util files in your python_tests()
target, and perhaps you could actually have a test in your conftest.py
?
3. Change pytest_runner.py
to not fail if the tests were empty. I argue that this failure is a feature, though - it’s caught issues for me in the past. And Pants should generally emulate Pytest as much as possible.hundreds-father-404
08/12/2020, 11:19 PMhundreds-father-404
08/12/2020, 11:21 PMpython_tests()
doesn’t make sense for a conventional conftest.py
without any tests in it. What does timeout=120
mean for that type of file?
The key intuition is that now “targets are metadata for some files”, rather than “targets are a collection of files plus some metadata”hundreds-father-404
08/12/2020, 11:22 PMpython_tests()
python_library(name="conftest")
That’s not too horrible imo. Not great if you are a 1.x user upgrading to 2.x thowitty-crayon-22786
08/12/2020, 11:43 PMwitty-crayon-22786
08/12/2020, 11:43 PMaloof-angle-91616
08/12/2020, 11:45 PMaloof-angle-91616
08/12/2020, 11:46 PMaloof-angle-91616
08/12/2020, 11:47 PMtimeout=120
as wellwitty-crayon-22786
08/13/2020, 12:00 AMhundreds-father-404
08/13/2020, 12:08 AMit’s just that folks might not have done that in all casesYeah, this is precisely the issue. If your tests lived in their own dedicated folder, it’s common to only put this in your BUILD file:
python_tests(
dependences=[...]
)
Now you have to go manually update every BUILD file to do this:
python_tests(
dependencies=[':conftest', ...]
)
python_library(name="conftest")
Although, actually, if you have --python-infer-conftests
on (the default), you would solely need to add the python_library(name="conftest")
target 🙂 You woulnd’t need to update the dependencies
of your python_tests
target because we’ll infer it. So, still not great, but not as horrible as beforehundreds-father-404
08/13/2020, 12:14 AMtests.py
in Django usually have actual tests in it? It’s not only util code, right?aloof-angle-91616
08/13/2020, 12:16 AMpolite-garden-50641
08/13/2020, 12:17 AMhundreds-father-404
08/13/2020, 12:18 AMenough-analyst-54434
08/13/2020, 12:23 AMhundreds-father-404
08/13/2020, 12:25 AMconftest.py
in the default globs for python_tests()
. If we remove that explicit entry, then it no longer will belong by default to a python_tests
targethundreds-father-404
08/13/2020, 12:25 AMconftest.py
doesn’t matchaloof-angle-91616
08/13/2020, 12:29 AMenough-analyst-54434
08/13/2020, 12:30 AMenough-analyst-54434
08/13/2020, 12:30 AMaloof-angle-91616
08/13/2020, 12:30 AMhundreds-father-404
08/13/2020, 12:30 AMwhich is to infer sibling or ancestor conftests.py files as test dependencies.Ah, there have been some changes to do exactly that in the past month, thanks to
--python-infer-conftests
optionhundreds-father-404
08/13/2020, 12:32 AM__init__.py
, via --python-infer-inits
. (Although that inference is a little more complex - it took a few iterations for us to get it right. tl;dr is that if no target owns the file, we will still include it in the chroot as an undeclared dependency)enough-analyst-54434
08/13/2020, 12:32 AMenough-analyst-54434
08/13/2020, 12:38 AMhundreds-father-404
08/13/2020, 12:40 AM--python-infer-conftests
would generate a subtarget from whatever the owner was. It doesn’t care if it’s a python_library
vs. a python_tests
target; it will generate the new target from whatever the original was
The real issue is the enormous model change in https://github.com/pantsbuild/pants/pull/10511. Now, we run tests one-file-at-a-time, over every file belonging to the python_tests
target. Because python_tests
defaults to conftest.py
being in its default globs, it was common for that to be included in the target.hundreds-father-404
08/13/2020, 12:41 AM--python-infer-contests
is really relevant is that it makes the solution less painful than it would have otherwise been. As described in https://github.com/pantsbuild/pants/pull/10603, most users won’t need to touch their dependencies
fields due to this change - inference will do the right thingjolly-midnight-72759
10/22/2020, 2:18 PMpython_test
target type?hundreds-father-404
10/22/2020, 2:45 PM