You can subclass DjangoTestSuiteRunner and override the setup_databases and teardown_database methods to pass.
Create a new settings file and set TEST_RUNNER for the new class you just created. Then, when you run the test, specify a new settings file with the --settings flag.
Here is what I did:
Create a custom test suit runner similar to this:
from django.test.simple import DjangoTestSuiteRunner class NoDbTestRunner(DjangoTestSuiteRunner): """ A test runner to test without database creation """ def setup_databases(self, **kwargs): """ Override the database creation defined in parent class """ pass def teardown_databases(self, old_config, **kwargs): """ Override the database teardown defined in parent class """ pass
Create custom settings:
from mysite.settings import *
When you run your tests, run them, as shown below, with the --settings flag set for your new settings file:
python manage.py test myapp --settings='no_db_settings'
UPDATE: April / 2018
Starting with Django 1.8, the django.test.simple.DjangoTestSuiteRunner module django.test.simple.DjangoTestSuiteRunner been moved to 'django.test.runner.DiscoverRunner' .
For more information, check the official documentation section for custom tests.
mohi666 Aug 10 2018-11-11T00: 00Z
source share