Write Django unit test fast ( fast database access, without database access, without create test database)
Sometimes, when running Django unit test , Django would generate test database. If your DB (e.g., MySQL ) server is remote, it is slow. To fast this process, we can use in-memory database locally for test.
Add following lines into settings.py
if 'test' in sys.argv:
SOUTH_TESTS_MIGRATE = False
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
}
DATABASES['qiche'] = {
'ENGINE': 'django.db.backends.sqlite3',
}
Reference:
http://www.slideshare.net/cordiskinsey/djangocon-2013-how-to-write-fast-and-efficient-unit-tests-in-django#
Add following lines into settings.py
if 'test' in sys.argv:
SOUTH_TESTS_MIGRATE = False
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
}
DATABASES['qiche'] = {
'ENGINE': 'django.db.backends.sqlite3',
}
Note that we disable South app for test. Because for multiple databases, the unit test may have error as
"DatabaseError: no such table: south_migrationhistory"
"DatabaseError: no such table: south_migrationhistory"
Reference:
http://www.slideshare.net/cordiskinsey/djangocon-2013-how-to-write-fast-and-efficient-unit-tests-in-django#
Comments
Post a Comment