The problem in my case was, that I've overridden the default creation of test database by Django, when running the tests. This happened by obsolete pytest fixture
that i had in my conftest.py
. As @willeM_ Van Onsem confirmed, Django by default creates a test database by appending test_
to the name of your default to use database.
In order to check which database are you using, just add a print statement into a test case:
from django.db import connection
connection.settings_dict["NAME"]
This will NOT print your default database name, but will print the database name of the currently used database.
In my case, my database configuration ended up like:
DATABASES = {
'default': {
"NAME": "localDatabase",
"ENGINE": "django.contrib.gis.db.backends.postgis",
"USER": "test",
"PASSWORD": "test",
"HOST": "127.0.0.1",
"PORT": "5432",
},
}
and when running the tests, the currently used database name is - "test_localDatabase".
As you can see, I have removed the "TEST"
key property from DATABASES
, because it overrides the default Django logic of generating a new name for the test database.