1 from django
.test
.simple
import DjangoTestSuiteRunner
2 from django
.conf
import settings
5 # http://djangosnippets.org/snippets/2211/
7 class MygpoTestSuiteRunner(DjangoTestSuiteRunner
):
9 Test runner that doesn't create or destroy a test database (it requires
10 a pre-setup database), and is able to skip some tests according to
14 def __init__(self
, *args
, **kwargs
):
15 self
.EXCLUDED_APPS
= getattr(settings
, 'TEST_EXCLUDE', [])
16 settings
.TESTING
= True
17 super(MygpoTestSuiteRunner
, self
).__init
__(*args
, **kwargs
)
20 def build_suite(self
, *args
, **kwargs
):
21 suite
= super(MygpoTestSuiteRunner
, self
).build_suite(*args
, **kwargs
)
22 if not args
[0] and not getattr(settings
, 'RUN_ALL_TESTS', False):
25 pkg
= case
.__class
__.__module
__.split('.')[0]
26 if pkg
not in self
.EXCLUDED_APPS
:
32 def setup_databases(*args
, **kwargs
):
33 from django
.db
import connections
36 for alias
in connections
:
37 connection
= connections
[alias
]
38 # If the database is a test mirror, redirect it's connection
39 # instead of creating a test database.
40 if connection
.settings_dict
['TEST_MIRROR']:
41 mirrors
.append((alias
, connection
))
42 mirror_alias
= connection
.settings_dict
['TEST_MIRROR']
43 connections
._connections
[alias
] = connections
[mirror_alias
]
45 old_names
.append((connection
, connection
.settings_dict
['NAME']))
47 # don't create a test-database, because we require
49 connection
.creation
.connection
.settings_dict
['NAME'] = \
50 'test_' + connection
.creation
.connection
.settings_dict
['NAME']
51 connection
.creation
.connection
.features
.confirm()
52 #connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
54 return old_names
, mirrors
56 def teardown_databases(*args
, **kwargs
):
59 def create_auth_string(username
, password
):
61 credentials
= base64
.encodestring("%s:%s" % (username
, password
)).rstrip()
62 auth_string
= 'Basic %s' % credentials