Hi all. I don’t know, I find the Pants documentati...
# general
c
Hi all. I don’t know, I find the Pants documentation about where to put things, and what the syntax looks like, very confusing. I’m trying to add
extra_requirements
so I can get pytest to use the requests module with something like this
extra-requirements=["requests==2.28.1"]
in my
pants.toml
file. But that doesn’t address the problem that the request module isn’t found when I write the test. :( What is the syntax and where does it go?
w
rather than telling
pytest
in particular that you need
requests
, the goal is for Pants to infer that a particular file that has an
import requests
needs requests.
if after running
./pants tailor
, you see a bunch of warnings about failures to infer deps, those will be very important to fix.
c
Thanks @witty-crayon-22786 , that helped a lot. I’m still confused about the syntax I mentioned, but at the moment I’ve got bigger fish to fry. 🙂
p
the
extra-requirements
is more for stuff like pytest plugins, for example, in our repo it looks like this:
Copy code
[pytest]
version = "pytest==7.2.0"
extra_requirements.add = [
  "pygments>=2.13.0",
  "pytest-icdiff"
]
c
Maybe you can help me with something else. If I’ve got a directory structure where
project
and
tests
are siblings, how do I inform test code how to import modules from the
project
folder?
p
note the
.add
on the option.
c
@polite-garden-50641, thanks! Does that snippet go in the
pants.toml
file (not
pyproject.toml
)?
yes, this is from our pants.toml
h
Re this:
Maybe you can help me with something else. If I’ve got a directory structure where project and tests are siblings, how do I inform test code how to import modules from the project folder?
The key concept is source roots. As long as those are configured, Pants will be able to find and knit together imports without you having to do anything special
So you don’t need to inform test code how to import from project, exactly, you just need project’s source root to be set up correctly, and when pants sees an import in the test code it’ll know how to map it back to the project code that provides that import