I have a multistage docker image as below.
# syntax=docker/dockerfile:1
FROM python:3.11 as DEP_BUILDER
ENV PYTHONFAULTHANDLER=1
PYTHONUNBUFFERED=1
PYTHONHASHSEED=random
PIP_NO_CACHE_DIR=off
PIP_DISABLE_PIP_VERSION_CHECK=on
PIP_DEFAULT_TIMEOUT=100
POETRY_CACHE_DIR='/var/cache/pypoetry'
POETRY_HOME='/usr/local'
ARG POETRY_VERSION=1.8.3
WORKDIR /venv
RUN apt-get update && apt-get install -y curl
RUN curl -sSL https://install.python-poetry.org | python3 -
COPY pyproject.toml /venv/
RUN python -m venv .venv
RUN . .venv/bin/activate &&
poetry config virtualenvs.in-project true &&
poetry install --no-interaction --no-ansi --only main
FROM python:3.11
WORKDIR /server
COPY /app /server/app
COPY /tests /server/tests
COPY --from=DEP_BUILDER /venv/.venv ./.venv
ENV PATH="/server/.venv/bin:$PATH"
CMD ./.venv/bin/python3 -m pytest tests
While in my local computer running pytest
works fine, when doing it inside Docker I get the following error:
Attaching to app-1
app-1 | ImportError while loading conftest '/server/tests/conftest.py'.
app-1 | tests/conftest.py:10: in <module>
app-1 | from test.support.os_helper import EnvironmentVarGuard
app-1 | E ModuleNotFoundError: No module named 'test'
app-1 exited with code 4
Could someone be so kind to explan why a module that is supposed to be a Python built-in is inaccessible from inside the image?
Thank you very much