speed up test execution by using in memory files and md5 password hashes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
j3d1 2023-06-28 18:40:22 +02:00
parent f738f5f485
commit 816543a0ab
2 changed files with 43 additions and 0 deletions

View file

@ -149,7 +149,29 @@ USE_TZ = True
STATIC_ROOT = 'staticfiles' STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/' STATIC_URL = '/static/'
MEDIA_ROOT = 'userfiles'
MEDIA_URL = '/media/'
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STORAGES = {
'default': {
'BACKEND': 'django.core.files.storage.FileSystemStorage',
'OPTIONS': {
'base_url': MEDIA_URL,
'location': BASE_DIR / MEDIA_ROOT
},
},
'staticfiles': {
'BACKEND': 'django.core.files.storage.FileSystemStorage',
'OPTIONS': {
'base_url': STATIC_URL,
'location': BASE_DIR / STATIC_ROOT
},
},
}
TEST_RUNNER = 'backend.test_runner.FastTestRunner'

View file

@ -0,0 +1,21 @@
from django.conf import settings
from django.test.runner import DiscoverRunner
class FastTestRunner(DiscoverRunner):
def setup_test_environment(self):
super(FastTestRunner, self).setup_test_environment()
# Don't write files
settings.STORAGES = {
'default': {
'BACKEND': 'django.core.files.storage.InMemoryStorage',
'OPTIONS': {
'base_url': '/media/',
'location': '',
},
},
}
# Bonus: Use a faster password hasher. This REALLY helps.
settings.PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
)