freezing-fall-2672
08/29/2023, 7:04 AMpants test :: is:
pants test ::
09:00:12.68 [ERROR] Completed: Run Pytest - src/py/app/tests.py:tests - failed (exit code 2).
============================= test session starts ==============================
platform darwin -- Python 3.11.5, pytest-7.0.1, pluggy-1.0.0
rootdir: /private/var/folders/ll/98hnvg_n5l3by0224q_qybc40000gn/T/pants-sandbox-5tufoo
plugins: xdist-2.5.0, anyio-3.7.1, forked-1.6.0, cov-3.0.0
collected 0 items / 1 error
==================================== ERRORS ====================================
_____________________ ERROR collecting src/py/app/tests.py _____________________
ImportError while importing test module '/private/var/folders/ll/98hnvg_n5l3by0224q_qybc40000gn/T/pants-sandbox-5tufoo/src/py/app/tests.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
src/py/app/tests.py:1: in <module>
from fastapi.testclient import TestClient
/Users/elmcrest/.cache/pants/named_caches/pex_root/venvs/ae0da83a0d64465b37a4d1ecad90e3717130f3f3/627db8b23588181684416f34c8d0a18060f35f65/lib/python3.11/site-packages/fastapi/testclient.py:1: in <module>
from starlette.testclient import TestClient as TestClient # noqa
/Users/elmcrest/.cache/pants/named_caches/pex_root/venvs/ae0da83a0d64465b37a4d1ecad90e3717130f3f3/627db8b23588181684416f34c8d0a18060f35f65/lib/python3.11/site-packages/starlette/testclient.py:16: in <module>
import httpx
E ModuleNotFoundError: No module named 'httpx'
- generated xml file: /private/var/folders/ll/98hnvg_n5l3by0224q_qybc40000gn/T/pants-sandbox-5tufoo/src.py.app.tests.py.tests.xml -
=========================== short test summary info ============================
ERROR src/py/app/tests.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.28s ===============================
you can find all the code here https://github.com/elmcrest/py_in_my_pants
my goal with this project is to better understand how pants works 🙂refined-addition-53644
08/29/2023, 7:20 AMfastapi[all] not just fastapi to access all the test related stuff and httpxfreezing-fall-2672
08/29/2023, 7:21 AMfreezing-fall-2672
08/29/2023, 7:21 AMrefined-addition-53644
08/29/2023, 7:23 AMrefined-addition-53644
08/29/2023, 7:24 AMfreezing-fall-2672
08/29/2023, 7:24 AMfreezing-fall-2672
08/29/2023, 7:24 AMfreezing-fall-2672
08/29/2023, 7:26 AMfreezing-fall-2672
08/29/2023, 7:27 AMrefined-addition-53644
08/29/2023, 7:27 AMfreezing-fall-2672
08/29/2023, 7:28 AMfreezing-fall-2672
08/29/2023, 7:29 AMrefined-addition-53644
08/29/2023, 7:32 AMfreezing-fall-2672
08/29/2023, 7:33 AMfastapi in requirements.txtfreezing-fall-2672
08/29/2023, 7:34 AMhttpx in the requirements at allfreezing-fall-2672
08/29/2023, 7:34 AMrefined-addition-53644
08/29/2023, 7:43 AMfrom fastapi.testclient import TestClient
It will only use fastapi and the associated transitive dependencies when running this test file and it assumes that any other transitive dependencies in this package are included inside fastapi. If the package doesn't properly define transitive dependencies then pants will complain like the error you got.
TestClient comes from httpx which pants doesn't know since it's not defined as transitive dependencies for fastapi but as extras fastapi[all].freezing-fall-2672
08/29/2023, 9:36 AMfreezing-fall-2672
08/29/2023, 9:40 AMfreezing-fall-2672
08/29/2023, 10:13 AMpants test ::
12:13:45.29 [ERROR] 1 Exception encountered:
Engine traceback:
in `test` goal
ValueError: The explicit dependency `src/py:reqs#httpx` of the target at `src/py:reqs#fastapi` does not provide enough address parameters to identify which parametrization of the dependency target should be used.
Target `src/py:reqs` can be addressed as:
* src/py:reqs
* src/py:reqs#fastapi
* src/py:reqs#pytest
* src/py/requirements.txt:reqsfreezing-fall-2672
08/29/2023, 11:00 AMfreezing-fall-2672
08/29/2023, 11:02 AMfreezing-fall-2672
08/29/2023, 11:02 AM