Reputation: 8158
When using sqlite for django you can checkout your application from source control and run the unit tests without needed to do anything special. But when you switch to using mysql as your database all of the sudden you need to create a database. Why do I need to do this? This is especially weird since the unit tests won't even use that database, they will instead create their own by prefixing the name with 'test_'.
Upvotes: 3
Views: 325
Reputation: 479
I use almost the same solution for test, like @Simon Bächler, but instead of real database
'NAME': 'test',
I use
'NAME':' :memory:,
So it use memory to handle test operations, and thats why it doesn't always create/update/delete the db.
Upvotes: 1
Reputation: 1429
If you run tests frequently put the following code in your settings.py:
import sys
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test'
}
}
Upvotes: 1
Reputation: 4656
This is because Django loads the settings.py file for running the test suite. You can create a separate settings.py file and use it at the time you run the tests. As an example from the django site:
--settings=test_sqlite
assuming you had a settings.py file called test_sqlite.
Go here for more information:
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
Upvotes: 1