Running a coverage test in a Docker container for Django

I am trying to use the coverage tool to measure the code coverage of my Django app, when I test it locally it works fine, but when i pushed to github, i got some errors in travis, here is my docker-compose file:

backend:
 container_name: backend_dev_blog
 build: ./backend
 command: "sh -c /start_dev.sh"
 volumes:
   - ./backend:/backend
 ports:
   - "8000:8000"
 networks:
   - main
 environment:
   - DB_HOST=db
   - DB_NAME=blog
   - DB_USER=postgres
   - DB_PASS=supersecretpassword
 depends_on:
  - db

thank you for any help

Hey @SolarUltima,

Your permission issue is most likely due to the fact you have a volume seemingly entitled (./backend:/backend) and that you are using a user in your Docker container which does not have the proper permissions to write on this volume via (USER user).

Since you probably can’t change the permissions on the Travis directory ./backend, you could try to change the user which is used to write files to that location, this would be the fastest solution. This is easy to do, especially with docker-compose:

backend:
 container_name: backend_dev_blog
 build: ./backend
 command: "sh -c /start_dev.sh"
 user: root
 volumes:
   - ./backend:/backend
 ports:
   - "8000:8000"
 networks:
   - main
 environment:
   - DB_HOST=db
   - DB_NAME=blog
   - DB_USER=postgres
   - DB_PASS=supersecretpassword
 depends_on:
  - db

This should do it, let me know if it doesn’t and I’ll help you further.