brash-student-40401
09/21/2022, 7:52 PMimport fastapi
with ModuleNotFoundError: No module named 'requests'
, which is a dependency of FastAPI. I tried explicitly adding requests
to my requirements.txt
and rebuilding the lock file, but it didn't clear the error. This seems funny to me - the code I am trying to test (using FastAPI) builds and runs fine, it's only the test itself that's failing on this import. Any advice? Some more details in ๐งตbrash-student-40401
09/21/2022, 7:53 PMImportError while importing test module '/tmp/process-executionq8o3SZ/src/services/dandelion/tests/test_app.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
src/services/dandelion/tests/test_app.py:3: in <module>
from fastapi.testclient import TestClient
/home/vscode/.cache/pants/named_caches/pex_root/venvs/s/42335c17/venv/lib/python3.8/site-packages/fastapi/testclient.py:1: in <module>
from starlette.testclient import TestClient as TestClient # noqa
/home/vscode/.cache/pants/named_caches/pex_root/venvs/s/42335c17/venv/lib/python3.8/site-packages/starlette/testclient.py:15: in <module>
import requests
E ModuleNotFoundError: No module named 'requests'
I also tried adding this to the BUILD
, but it didn't help:
python_requirement(
name="requests",
requirements=["requests"],
)
brash-student-40401
09/21/2022, 7:54 PMenough-analyst-54434
09/21/2022, 7:57 PMfast-nail-55400
09/21/2022, 7:57 PMbrash-student-40401
09/21/2022, 8:24 PMenough-analyst-54434
09/21/2022, 8:25 PMenough-analyst-54434
09/21/2022, 8:26 PMbrash-student-40401
09/21/2022, 8:28 PMdefault.lock
that it is asking for requests:
"project_name": "fastapi",
"requires_dists": [
...
"requests<3.0.0,>=2.24.0; extra == \"all\"",
"requests<3.0.0,>=2.24.0; extra == \"test\"",
enough-analyst-54434
09/21/2022, 8:29 PMenough-analyst-54434
09/21/2022, 8:29 PMfastapi[test]
?enough-analyst-54434
09/21/2022, 8:29 PMenough-analyst-54434
09/21/2022, 8:31 PMbrash-student-40401
09/21/2022, 8:31 PMenough-analyst-54434
09/21/2022, 8:31 PMbrash-student-40401
09/21/2022, 8:32 PMenough-analyst-54434
09/21/2022, 8:32 PMfastapi[test]
instead of fastapi
enough-analyst-54434
09/21/2022, 8:32 PMenough-analyst-54434
09/21/2022, 8:33 PMbrash-student-40401
09/21/2022, 8:33 PMenough-analyst-54434
09/21/2022, 8:33 PMbrash-student-40401
09/21/2022, 8:33 PMbrash-student-40401
09/21/2022, 8:37 PMenough-analyst-54434
09/21/2022, 8:38 PMshy-advantage-49800
09/22/2022, 6:21 AMfastapi[test]
, but you can use fastapi[all]
. The "test" extra install the packages needed for test itself. It's not related to the TestClient
. The testclient only needs the requsts
package, which is included in the "all" extra.