Hello, I am trying to use <Moto> to mock out AWS ...
# general
r
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
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
Awesome would have been a while before I figured that out. Following worked a treat:
Copy code
python_tests(
   name="test"
   dependencies=["//:setuptools"],
)
h
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
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
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
@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