very random question.. is it normal for pants v1.3...
# general
w
very random question.. is it normal for pants v1.30 to take so long to run tests? I mean.. somewhere around 30 minutes.. keeps hanging there ->
Copy code
============== test session starts ===============
platform darwin -- Python 3.7.8, pytest-5.3.5, py-1.9.0, pluggy-0.13.1
cachedir: .pants.d/test/pytest/.pytest_cache
rootdir: /Users/lzfnyy/Projects/clueless, inifile: /dev/null
plugins: cov-2.8.1, sanic-1.6.1, timeout-1.3.4
h
No, unless you expect your test to take a really long time. How long would you expect? It might legitimately be a hung test. You can set
timeout=120
(in seconds) to the
python_tests()
target https://www.pantsbuild.org/docs/python-test-goal#using-timeouts
šŸ˜¢ 1
w
it might be something off with these crazy dependenciesā€¦ tensorflow and whatnot
šŸ™ƒ 1
h
Is it a new test? Flaky tests are the worst, we had a couple of them from the v1 engine (now removed) and they really slowed down our CI Iā€™m wondering why this only recently might have started happening
w
Iā€™m not sure, Iā€™ll have to debug these.. I think after someone added
pandas
it started throwing a couple of odd warnings here and there.. same for Tensorflow.. I just wanted to make sure that
pants
wasnt really causing anything before diving in
h
Generally, never say never. There could be an issue with pants that is causing it to hang that we arenā€™t aware of. We donā€™t know of anything that would cause a hang, but certainly possible Is this in CI or locally? It might be interesting to run, say,
top
, to see if the CPU is in active use
Also I didnā€™t ask to clarify. Is this deterministic, or flaky?
w
Itā€™s deterministic and I think it is also happening when using
pytest tests
so Iā€™m almost sure that
pants
isnt the culprit but Iā€™ll update you guys on this matter
šŸ‘ 1
h
Cool. I mean still frustrating, but determinism is much better. Flaky tests drive me wild. I think everyoneā€™s different here, but I personally really like using printing/logging to identify at what point things start hanging. ā€œHow farā€ can you get in your code before it hangs.
w
hey @hundreds-father-404 Iā€™m investigating the tests here and I was wondering if itā€™s possible to set the plugins inside a BUILD file instead of
pants.toml
. I have a couple of tests that are dependent of
pytest-sanic
but everything else isnā€™t.
h
You could treat the plugins like normal 3rd-party requirements to those
python_tests
targets. See https://www.pantsbuild.org/docs/python-third-party-dependencies#defining-inline-requirements for how to define those requirements inline, if you donā€™t want them to be in a global
requirements.txt
. Then, add the targets to the
dependencies
field. Note that dep inference wonā€™t ever be able to infer the deps, as they arenā€™t used in import statements. This is how we load
pytest-django
in Toolchainā€™s repo
ā¤ļø 1
w
is the toolchain repo oss too?
h
Itā€™s not. A lot of what we work on gets open sourced, though
w
haha just wanted to take a peak on your BUILD files šŸ¤£
h
I can give you a sample! Almost every one of our BUILD files looks like this lol thanks to dep inference:
Copy code
python_library()

python_tests(name='tests')
A more complex example
Copy code
python_library()

python_tests(
  name='tests',
  dependencies = [
    '3rdparty/python:pytest-django',  # Test time requirement.
    'src/python/toolchain/buildsense',  # Used in `conftest.py`.
     ...
  ],
)
w
oh yeah, awesome Iā€™ve been wanting to ask about that.. I did notice those empty
python_library()
and I have a couple but Iā€™m not sure what theyā€™re doing šŸ˜•
h
Itā€™s telling Pants ā€œThis is Python production code here that you should know about. It uses the defaults for everything. Nothing special going on.ā€ See https://www.pantsbuild.org/docs/targets#default-field-values
Thanks to dep inference, BUILD files can now basically be empty, except for when they have metadata that deviates from the default. For example, you depend on some JSON files that dep inference canā€™t pick up. Or you depend on a runtime dependency like a Pytest plugin. Or you want a custom
compatibility
for Python interpreter versions Btw,
./pants dependencies path/to/file.py
is helpful to see what Pants is inferring.
w
oh thatā€™s really helpful
sorry about asking these silly questions, Iā€™ll do a second read on docs
h
I was originally honestly a bit opposed to dep inference and favored buildgen, which writes to disk. And then I realized how much I like how BUILD files read now, that theyā€™re much more declarative because 95% of the noise is removed
sorry about asking these silly questions,
Not at all silly. We made some pretty fundamental changes to how you interact with Pants in 2.0, with a) dependency inference and b) ā€œfile-level addressesā€ that allow you to operate with file-level precision, e.g. depend on just a file (https://www.pantsbuild.org/docs/how-to-upgrade-pants-2-0#files-are-now-the-atomic-unit-rather-than-targets-130-vs-20) It took us about 2-3 months of iterating on different designs. Definitely not silly or trivial with questions like that
Documented the alternative way to depend on plugins at https://www.pantsbuild.org/docs/python-test-goal#pytest-version-and-plugins Lmk if you have any feedback on it šŸ™‚