Hello, 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?
A:
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
Seth
2010-10-07 22:36:18
Do I need to change my manage.py file to reflect this? My application doesn't seem to be prepared to have this as a parameter.
highriseo
2010-10-08 14:43:45
Nope, you just need to create a new settings file and specify the module name. It's best to have the file `from settings import *` to retain all of your normal settings. See `python manage.py help`.
Seth
2010-10-08 17:10:18
+1
A:
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
.
Manoj Govindan
2010-10-08 06:22:21
I'm not actually running the testing suite. I'm trying to be able to switch between local testing and aws testing.
highriseo
2010-10-08 15:16:58