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

rich-church-77699

08/05/2021, 4:10 PM
Hello, I am trying to use Moto to mock out AWS services for my unit tests. When I attempt to run the unit tests with
pants
they fail due to the error below, which appears to be due to missing
setuptools
in the
pants virtualenv
I am using
poetry version 1.2.0a2
to generate a
constraints.txt
which contains
setuptools
as a requirement Is there a reason why pants is not installing setuptools in the virtualenv?
Copy code
import pkg_resources
EΒ Β  ModuleNotFoundError: No module named 'pkg_resources'
/home/vagrant/.cache/pants/named_caches/pex_root/venvs/short/041f67f1/lib/python3.8/site-packages/moto/core/models.py:8: ModuleNotFoundError
c

clean-city-64472

08/05/2021, 4:18 PM
I would try adding setuptools as an explicit dependency in your BUILD file
πŸ‘ 1
βž• 1
It looks like
moto
does not include setuptools in its requirements (even though it should)
πŸ‘ 2
r

rich-church-77699

08/05/2021, 6:46 PM
Awesome would have been a while before I figured that out. Following worked a treat:
Copy code
python_tests(
   name="test"
   dependencies=["//:setuptools"],
)
h

happy-kitchen-89482

08/05/2021, 8:05 PM
Glad that worked, thanks for the tip @clean-city-64472
There are other dists that fail to require
setuptools
when they should, moto is not the only culprit.
c

clean-city-64472

08/05/2021, 8:06 PM
yeah i've hit this a few times - but if you had a single other dep in that target that did include setuptools properly you wouldn't even notice
πŸ‘ 1
r

rich-church-77699

08/06/2021, 9:45 AM
Also worth adding that I had to use a preview version of poetry
version 1.2.0a2
as when exporting the lock file to
constraints.txt
in current versions of poetry it would not export
setuptools
it was resolved here Using the preview version of poetry introduced another issue, they have renamed where dev dependencies are stored in
pyproject.toml
to
[tool.poetry.group.dev.dependencies]
which means pants can't pick up the package until it is manually moved under
[tool.poetry.dev-dependencies]
h

hundreds-father-404

08/06/2021, 1:57 PM
@rich-church-77699 that poetry dep groups feature was added this week and will be going out in today's 2.6 and 2.7 release :)
πŸ™Œ 1
3 Views