Testdriven.io: Test-Driven Development with FastAPI and Docker Pytest in docker runs tests of env files

180 Views Asked by At

I am following https://testdriven.io/courses/tdd-fastapi/pytest-setup/, but when running

docker-compose exec web python -m pytest

for the first time, I get

collected 212 items / 24 errors

instead of the expected 0 items.

The short test summary info shows among others

ERROR env/Lib/site-packages/h11/tests/test_against_stdlib_http.py
ERROR env/Lib/site-packages/h11/tests/test_connection.py
ERROR env/Lib/site-packages/h11/tests/test_events.py
ERROR env/Lib/site-packages/h11/tests/test_headers.py

so I believe my env folder in project is being copied in the container, however my .dockerignore file is present in project containing the following four lines:

env
.dockerignore
Dockerfile
Dockerfile.prod

I committed my current progress to this GitHub Repo ifyou want to take a look.

Does anyone have an idea what I am doing wrong?

1

There are 1 best solutions below

0
On

I don't have the required "50 reputation" yet to comment so this has to be an "answer".

In the "getting started" section (https://testdriven.io/courses/tdd-fastapi/getting-started/), almost at the very end, there's a line "Exit then remove the virtual environment as well". Maybe you forgot to remove the virtual environment at that time? I'm not yet through the whole thing (actually, just starting the pytest setup), but I think the idea is to keep the volume with your source code mounted so that you can test from within the docker container.