I have a gihub-actions
file with a part to run pytest
via poetry
:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10',]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
pip install requests
if [ -f pyproject.toml ]; then poetry install; fi
- name: Test with pytest
run: |
poetry run pytest -s
However, despite the fact that I’ve installed the dependencies via poetry
as well as requests
separately via pip
still it throws the following error in github-actions
runner:
Run poetry run pytest -s
ImportError while loading conftest '/home/runner/work/backend-holoplot/backend-holoplot/tests/conftest.py'.
tests/conftest.py:4: in <module>
from .client import override_get_db, engine
tests/client.py:3: in <module>
from fastapi.testclient import TestClient
../../../.cache/pypoetry/virtualenvs/production-api-4u0DyUfz-py3.10/lib/python3.10/site-packages/fastapi/testclient.py:1: in <module>
from starlette.testclient import TestClient as TestClient # noqa
../../../.cache/pypoetry/virtualenvs/production-api-4u0DyUfz-py3.10/lib/python3.10/site-packages/starlette/testclient.py:16: in <module>
import requests
E ModuleNotFoundError: No module named 'requests'
Error: Process completed with exit code 4.
3
Answers
Personally solved the issue by adding
requests
viapoetry
as well instead ofpip
:Usually, Poetry will install things in a separate environment. So if you install something with
pip
later thepoetry run ...
environment will not see those dependencies.You can install
requests
inpoetry
, or you could configurepoetry
to not create a virtual environment in CIfor example:
Will run on poetry, but you could configure to not use a virtual environment with:
try this: