Speeding up Django tests Disable migrations during tests
Speeding up Django tests Disable migrations during tests
Running all migrations before the testrun can take a lot of time. For some reason, they are very slow. Running 50 migrations could easily take more than 1 minute! Fourtunately, disabling migrations is very easy. Just add the following code to the tests settings file:
# Disable migrations when running tests
MIGRATION_MODULES = {
app[app.rfind('.') + 1:]: 'your_app.migrations_not_used_in_tests'
for app in INSTALLED_APPS
}
TEST_RUNNER = 'your_app.test_runner.CustomDiscoverRunner'
from django.test.runner import DiscoverRunner
from myapp.management.commands._setup_functions import create_groups
class CustomDiscoverRunner(DiscoverRunner):
def setup_databases(self, **kwargs):
result = super(CustomDiscoverRunner, self).setup_databases(**kwargs)
create_groups()
return result
download file now
Comments
Post a Comment