Cliff
Cliff

Reputation: 11238

Django separate DB engine for unit tests

I am new to Django and following several tutorials. I created a separate app for functional testing. I also setup a postgres DB engine for my prod DBMS but for testing I'd like to use SQLite3 in memory. Could someone tell me how to override the prod DB with another settings.py file? Where would I put the override file, in my functional test app folder? How does Django know which settings to use for prod vs. testing? Any help appreciated, thanks!

Upvotes: 0

Views: 216

Answers (2)

Dima Bildin
Dima Bildin

Reputation: 1553

As an option: Create a file names settings_test.py that contains something like:

from settings import * # if your main settings file is settings.py
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
# and whatever other settings like db name etc.

Then run tests with the settings:

./manage.py test --settings=settings_test

Upvotes: 4

Related Questions