After running tests where I am creating rows in the database, I noticed that the current database is used instead of a test database like I think is the default behavior of django. Unfortunately, I haven't been able to figure out how to fix this behavior.
This is currently in the settings.py
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ["POSTGRES_NAME"],
"USER": os.environ["POSTGRES_USER"],
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
"HOST": os.environ["POSTGRES_HOST"],
"PORT": os.environ["POSTGRES_PORT"],
}
}
but when adding "TEST": {"NAME": "test_database"}, it still seems to run on the main database.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ["POSTGRES_NAME"],
"USER": os.environ["POSTGRES_USER"],
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
"HOST": os.environ["POSTGRES_HOST"],
"PORT": os.environ["POSTGRES_PORT"],
"TEST": {
"NAME": "test_database",
}
}
}
How can I get it so the tests write to a fresh test database?
Aucun commentaire:
Enregistrer un commentaire