From 2743017e3d7475dfc4e6f95a6a8bcf528c03be5d Mon Sep 17 00:00:00 2001 From: Garima Ketan Chauhan Date: Wed, 2 Apr 2025 22:48:46 +0200 Subject: [PATCH] Update Dockerfile.test --- backend/tests/Dockerfile.test | 38 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/backend/tests/Dockerfile.test b/backend/tests/Dockerfile.test index 0d900f2..4beeb65 100644 --- a/backend/tests/Dockerfile.test +++ b/backend/tests/Dockerfile.test @@ -1,19 +1,33 @@ -FROM python:3.12-slim +# backend/tests/Dockerfile.test +FROM python:3.9-slim +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Set work directory (inside container) WORKDIR /app -# Install dependencies from requirements.txt -COPY ../requirements.txt /app/requirements.txt -RUN pip install --no-cache-dir -r requirements.txt +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* -# Install coverage (if not included in requirements.txt) -RUN pip install --no-cache-dir coverage +# Copy requirements from backend/ (parent of tests/) +COPY ../requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt +RUN pip install coverage # Explicit install if not in requirements.txt -# Copy the entire backend folder into the container -COPY .. /app/backend +# Copy necessary files from project root +COPY ../manage.py . +COPY ../your_app/ ./your_app # Replace 'your_app' with your Django app name +COPY ../pytest.ini . # If you have one +COPY .coveragerc . # If you have custom coverage config -# Set the working directory to the backend folder -WORKDIR /app/backend +# Copy tests +COPY ../tests/ ./tests # If you have tests outside the app -# Run tests with coverage -CMD ["bash", "-c", "pytest --cov=backend --cov-report=xml"] +# Command to run tests with coverage +CMD ["sh", "-c", "coverage run --source='.' manage.py test && coverage report && coverage xml"]