Hi everyone, I am starting with pants and trying t...
# general
p
Hi everyone, I am starting with pants and trying to resolve external file fixtures that are in central folder "<root>/fixtures" which is read by pytest tests in several python libraries "<root>/libXY/tests/test_XY.py". Is it possible to instruct pants to copy this folder into its temporary hermetic env so the paths are resolved correctly? Or do I have to rewrite all the paths?
👋 2
b
You can always use manual dependencies in your
BUILD.pants
files to instruct Pants what should also be in the sandbox. Usually though, that's brittle so you either: 1. Need to find out how to convince Pants to find those dependencies automatically 2. Have to change the paths/code so that 1. happens If you share a little more explicitly how pytest is configured to load fixtures from that path, we might be able to avoid 2 with existing facilities.
p
I define the fixtures in conftest like
Copy code
# conftest.py
DIR_PATH = os.path.dirname(os.path.realpath(__file__))

@pytest.fixture
def data():
    with open(f"{DIR_PATH}/../../fixtures/fixture.json", "r") as fh:
        return json.load(fh)
b
So we have the notion of giving a hearty try to matching strings to assets, if enabled: https://www.pantsbuild.org/v2.16/docs/reference-python-infer#assets This is done rather statically and dumbly, so it wouldn't match. If you're willing to assume CWD is <build root>, you might try enabling the feature and using the string
"<path/to/>fixtures/fixture.json"
where the
<path/to>
part is the parts between the build root and that directory
In every case, you'll also need to make sure there's a
file
target for the fixtures.
files(sounrce=["*.json"])
(or whatever makes most sense) in
BUILD
in the
fixtures
dir should do it
You'll know the inference works when you do
pants dependencies <path/to/conftest.py>
lists the correct file dependencies
p
OK, I will give it a try. Thanks for now