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

wooden-thailand-8386

09/22/2020, 6:41 PM
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

hundreds-father-404

09/22/2020, 6:54 PM
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

wooden-thailand-8386

09/22/2020, 7:07 PM
it might be something off with these crazy dependencies… tensorflow and whatnot
🙃 1
h

hundreds-father-404

09/22/2020, 7:09 PM
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

wooden-thailand-8386

09/22/2020, 8:04 PM
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

hundreds-father-404

09/22/2020, 8:08 PM
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

wooden-thailand-8386

09/22/2020, 8:25 PM
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

hundreds-father-404

09/22/2020, 8:31 PM
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

wooden-thailand-8386

09/23/2020, 8:35 PM
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

hundreds-father-404

09/23/2020, 8:39 PM
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

wooden-thailand-8386

09/23/2020, 8:41 PM
is the toolchain repo oss too?
h

hundreds-father-404

09/23/2020, 8:42 PM
It’s not. A lot of what we work on gets open sourced, though
w

wooden-thailand-8386

09/23/2020, 8:43 PM
haha just wanted to take a peak on your BUILD files 🤣
h

hundreds-father-404

09/23/2020, 8:45 PM
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

wooden-thailand-8386

09/23/2020, 8:47 PM
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

hundreds-father-404

09/23/2020, 8:48 PM
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

wooden-thailand-8386

09/23/2020, 8:55 PM
oh that’s really helpful
sorry about asking these silly questions, I’ll do a second read on docs
h

hundreds-father-404

09/23/2020, 8:59 PM
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 🙂
4 Views