tallowen
tallowen

Reputation: 4328

Changing the active database in django

i'm writing a testing application that i'm using to test the rest of my code base. What i'd like to be able to do for it is when i test using this manage.py command, automatically change to be logging to a different database. is there a good way to do this?

Upvotes: 0

Views: 136

Answers (2)

Manoj Govindan
Manoj Govindan

Reputation: 74795

Django automatically creates and drops a test database for you. Unless otherwise specified (we'll see how to in a second) this will be test_ + <the name of the database in the settings file>. So if your settings uses database foo, the tests will be executed against test_foo. No configuration changes are needed for this.

If you wish to execute tests against a custom database (rather than test_foo) you can do that by tweaking the TEST_NAME setting. You can add TEST_NAME to each dictionary in DATABASES.

Upvotes: 1

Seth
Seth

Reputation: 46473

Create a testing version of settings.py, and specify it on the command line when you run your test:

$ python manage.py test --settings=settings_test

Upvotes: 0

Related Questions