diff --git a/Dockerfile.test b/Dockerfile.test index 4a77a00db..2ff586185 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -1,4 +1,5 @@ # Test image for running backend and frontend tests +# syntax=docker/dockerfile:1.7 FROM python:3.13-slim AS backend-test WORKDIR /app @@ -8,10 +9,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ && rm -rf /var/lib/apt/lists/* -# Install Python dependencies including test dependencies +# Install Python dependencies including test dependencies. +# BuildKit cache mount makes subsequent builds re-use the pip download +# cache so the second build only does install work — the slow ~60-90s +# fetch step from the first build becomes ~5s. Requires DOCKER_BUILDKIT=1 +# (already set in test_docker.sh). COPY requirements.txt ./ COPY requirements-dev.txt ./ -RUN pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt -r requirements-dev.txt # Copy backend code COPY backend/ ./backend/ @@ -31,8 +37,14 @@ ENV PYTHONUNBUFFERED=1 ENV DATA_DIR=/app/data ENV TESTING=1 -# Default command runs pytest (excluding docker integration tests) -CMD ["pytest", "backend/tests/", "-v", "--tb=short", "-p", "no:cacheprovider", "-n", "30"] +# Default command runs pytest (excluding docker integration tests). +# -v dropped: 5300+ "PASSED foo::bar" lines per worker eat noticeable +# stdout I/O time and clutter test_docker.sh output. --tb=short still +# gives full failure tracebacks when something breaks. +# -n auto adapts to the host's vCPU count instead of hard-coding 30 — +# on a 2-vCPU CI / VM runner, -n 30 spawns 30 Python processes fighting +# for 2 cores, which is mostly IPC + import-thrash overhead. +CMD ["pytest", "backend/tests/", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"] # ------------------------------------------- # Frontend test stage diff --git a/docker-compose.test.yml b/docker-compose.test.yml index d5c8cf520..cf52e33ef 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -56,7 +56,9 @@ services: environment: - BAMBUDDY_TEST_URL=http://integration:8000 - TESTING=1 - command: ["pytest", "backend/tests/integration/", "-v", "--tb=short", "-p", "no:cacheprovider", "-n", "30"] + # -v dropped + -n auto so integration tests inherit the same noise / + # parallelism profile as the backend-test image (see Dockerfile.test CMD). + command: ["pytest", "backend/tests/integration/", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"] volumes: - ./backend:/app/backend:ro