Django tests hang in Docker: test database already exists
Django found the test database left by an earlier run and asks whether to delete it. In a script, in CI and in an agent's shell nobody answers that question, so the command waits forever. Run the tests with --noinput.
docker compose exec -T web python manage.py test --noinput
Without the flag Django stops at a question:
Got an error creating the test database: database "test_app" already exists
Type 'yes' if you would like to try deleting the test database 'test_app', or 'no' to cancel:
The question shows only when the command’s output goes straight to the screen. For me an AI agent ran the tests, and it gets the output once the command has ended. This one did not end, so it looked like tests hanging without a word. A | tail at the end does the same.
With the input closed (< /dev/null) Django does not wait; it ends with EOFError: EOF when reading a line.
Where the old database comes from: --keepdb leaves it, and for me it was pytest-django with --reuse-db, which I use every day. A manage.py test run after it meets its database.
checked: Django 5.2.16, PostgreSQL 17, Docker Compose 5.6.1