Hi all. I'm setting up pants on an existing Python...
# general
p
Hi all. I'm setting up pants on an existing Python project but am facing an issue when running tests. The issue is the following code:
import json
def get_module_json(module, file_name):
"""
Helped method to load a file
"""
file_name = "tests/" + module + "/jsons/" + file_name
with open(file_name) as file:
return json.load(file)
We're using this to load json payloads from various locations but since we're loading them like this pants is unable to detect these files and hence does not include them in the sandbox. So I need to know how I can include all files in my tests folder in pants sandbox (at least all json files). Thanks in advance.
c
you can use files target to make pants aware of these jsons: https://www.pantsbuild.org/docs/reference-files and then add them as a dependency to your test target
🙌 1
p
Thank you so much!
h
Yep - usually Pants can infer dependencies, but in this case the path to the file is computed at runtime, so static analysis can't determine it, so you need an explicit dep.
(Even if the dep could be inferred, you'd still need a
files()
target, but this explains why you need an explicit dep on it)