From 816543a0abb4f3e561a18d90d59d76d19a5697b6 Mon Sep 17 00:00:00 2001 From: jedi Date: Wed, 28 Jun 2023 18:40:22 +0200 Subject: [PATCH] speed up test execution by using in memory files and md5 password hashes --- backend/backend/settings.py | 22 ++++++++++++++++++++++ backend/backend/test_runner.py | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 backend/backend/test_runner.py diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 8fa1adb..ca776e8 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -149,7 +149,29 @@ USE_TZ = True STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' +MEDIA_ROOT = 'userfiles' +MEDIA_URL = '/media/' + # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field 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' diff --git a/backend/backend/test_runner.py b/backend/backend/test_runner.py new file mode 100644 index 0000000..fb131a9 --- /dev/null +++ b/backend/backend/test_runner.py @@ -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', + )