Django Tests 8x faster
I want to share this simple #tips that make my tests runs 3 times faster
My tests at the start it took 15.871s
1- Parallel Testing
python manage.py test --parallel
2- Keep Database
python manage.py test --parallel --keepdb
After this steps tests took 7.5s
3- custom settings
# file: my_project/settings/test_settings.py
# import the base settings
from my_project.settings import *
# stop logging
import logging
logging.disable(logging.CRITICAL)
# Stop debug
DEBUG = False
TEMPLATE_DEBUG = False
# Weak hashing but faster
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
]
# Just keep the needed middleware
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
]
# Sqlite for simple testing
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory'
}
}
python manage.py test --parallel --keepdb --settings=dj.settings.settings_test
After this step tests took 1.8s which is 8x faster :D