Skip to content

Commit 080f814

Browse files
committed
refactor: update Dockerfile and pyproject.toml to streamline test dependencies and ensure coverage is available in the backend container
1 parent 989fd18 commit 080f814

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.github/workflows/test-docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
3434
- name: Run tests with coverage
3535
run: |
36-
# Bootstrap pip inside the backend container and install dev deps (coverage, pytest)
37-
docker compose run --rm backend bash -lc "python - <<'PY'\nimport ensurepip, subprocess, sys\ntry:\n ensurepip.bootstrap()\nexcept Exception:\n pass\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '--no-cache-dir', 'coverage', 'pytest', 'pytest-asyncio'])\nPY\npython -m coverage run -m pytest --maxfail=1 -q --disable-warnings && python -m coverage xml -o coverage.xml && python -m coverage html -d coverage_html"
36+
# Bootstrap pip inside the backend container and install test/dev deps from pyproject (. [dev])
37+
docker compose run --rm backend bash -lc "python - <<'PY'\nimport ensurepip, subprocess, sys\ntry:\n ensurepip.bootstrap()\nexcept Exception:\n pass\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'])\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '--no-cache-dir', '.[dev]'])\nPY\npython -m coverage run -m pytest --maxfail=1 -q --disable-warnings && python -m coverage xml -o coverage.xml && python -m coverage html -d coverage_html"
3838
3939
- name: Upload coverage artifact
4040
uses: actions/upload-artifact@v4

backend/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,4 @@ COPY ./tests /app/tests
4141
RUN --mount=type=cache,target=/root/.cache/uv \
4242
uv sync
4343

44-
# Ensure coverage is available inside the uv-created virtualenv so test
45-
# commands like `python -m coverage` work when running inside the container.
46-
RUN /app/.venv/bin/python -m pip install --no-cache-dir coverage
47-
4844
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]

backend/pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ dev-dependencies = [
3838
"coverage<8.0.0,>=7.4.3",
3939
]
4040

41+
[project.optional-dependencies]
42+
dev = [
43+
"pytest<8.0.0,>=7.4.3",
44+
"pytest-asyncio",
45+
"coverage<8.0.0,>=7.4.3",
46+
]
47+
4148
[build-system]
4249
requires = ["hatchling"]
4350
build-backend = "hatchling.build"

0 commit comments

Comments
 (0)