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

few-alarm-32433

08/15/2020, 1:01 AM
hello, I have a python test that basically runs pants itself to enforce an invariant about the build tree (something along the lines of every module has a corresponding test). However, I expect that this test would fail once I turn on
chroot
. What is the canonical way to test the build tree itself? Or maybe there is a short-hand way to declare a dependency on pants + its build files?
h

hundreds-father-404

08/15/2020, 3:41 AM
Hey Remi 🙂 What version are you on? You can use
PantsRunIntegrationTest
from the
pantsbuild.pants.testutil
distribution. I’m still documenting it at https://www.pantsbuild.org/v2.0/docs/rules-api-testing, but tl;dr 1. add
pants_requirement(dist='pantsbuild.pants.testutil')
in a BUILD file. This will automatically use your
pants_version
. See https://www.pantsbuild.org/v2.0/docs/plugins-overview#building-in-repo-plugins-with-pants for a little more about that. 2. Add a new test that subclasses
PantsRunIntegrationTest
. See https://github.com/pantsbuild/pants/blob/6f243d7d206c0d49e897a1f1eacd0186dd9b755b/src/python/pants/help/help_integration_test.py#L10-L17 for an example of running the
help
goal.
(I’m asking what version because the behavior of
PantsRunIntegrationTest
changes a little. For some versions, it would expect a file called
pants.pex
to be present at your build root. More recently, that isn’t necessary)
f

few-alarm-32433

08/17/2020, 2:20 PM
I’m on pants 1.24, been chipping away at upgrading
❤️ 1
if PantsRunIntegrationTest is v2-specific I’m ok holding off, but it’s good to know there is a solution in the future.
h

hundreds-father-404

08/17/2020, 2:43 PM
It is not V2 specific. We’ve had it for a really long time - it’ll work with V1
👍 1
4 Views