Created
April 27, 2011 20:15
-
-
Save tganzarolli/945093 to your computer and use it in GitHub Desktop.
Generates a custom DjangoTestSuiteRunner that can bypassa the creation of a database instance, if the BYPASS_CREATION entry is set to yes, inside DATABASES dict.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test.simple import DjangoTestSuiteRunner | |
class ByPassableDBDjangoTestSuiteRunner(DjangoTestSuiteRunner): | |
def setup_databases(self, **kwargs): | |
from django.db import connections | |
old_names = [] | |
mirrors = [] | |
for alias in connections: | |
connection = connections[alias] | |
# If the database is a test mirror, redirect it's connection | |
# instead of creating a test database. | |
if connection.settings_dict['TEST_MIRROR']: | |
mirrors.append((alias, connection)) | |
mirror_alias = connection.settings_dict['TEST_MIRROR'] | |
connections._connections[alias] = connections[mirror_alias] | |
elif connection.settings_dict.get('BYPASS_CREATION','no') == 'no': | |
old_names.append((connection, connection.settings_dict['NAME'])) | |
connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive) | |
return old_names, mirrors |
For Django 1.6+, you can use DiscoverRunner instead of DjangoTestSuiteRunner, and it won't break
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
for Django 1.4 it should be: