Skip to content

Commit

Permalink
Fixed the testrunner database switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rusev committed Aug 1, 2011
1 parent ea3ee64 commit a53248b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.rst
Expand Up @@ -27,13 +27,14 @@ download the tarball and run ``python setup.py install``






3. Add your test database details in settings.py 3. Add your test database details in settings.py.


:: ::


DATABASES = { DATABASES = {
'default':{ 'default':{
'ENGINE':''}, 'ENGINE':'',
},
'test':{ 'test':{
'ENGINE': '', 'ENGINE': '',
'NAME': 'test_database', 'NAME': 'test_database',
Expand Down Expand Up @@ -116,3 +117,4 @@ Django 1.2+


nose nose



26 changes: 20 additions & 6 deletions quick_test/testrunner.py
Expand Up @@ -3,9 +3,10 @@
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.test.simple import DjangoTestSuiteRunner from django.test.simple import DjangoTestSuiteRunner
from django.db import connection
import nose.core import nose.core
from plugin import ResultPlugin from plugin import ResultPlugin
from django.db.backends import creation
from django.db import connection, DatabaseError


try: try:
any any
Expand Down Expand Up @@ -49,12 +50,21 @@ def run_tests(self, test_labels, extra_tests=None):
settings.DEBUG = False settings.DEBUG = False


self.setup_test_environment() self.setup_test_environment()



# Switch to the test database
old_name = settings.DATABASES['default']['NAME']

if settings.DATABASES['test']['NAME']:
settings.DATABASES['default']['NAME'] = settings.DATABASES['test']['NAME']
else:
settings.DATABASES['default']['NAME'] = creation.TEST_DATABASE_PREFIX + settings.DATABASES['default']['NAME']

connection.settings_dict["DATABASE_NAME"] = settings.DATABASES['default']['NAME']

try: try:
settings.DATABASES['default']['SUPPORTS_TRANSACTIONS'] = connection.creation._rollback_works() settings.DATABASES['default']['SUPPORTS_TRANSACTIONS'] = connection.creation._rollback_works()
settings.DATABASES['test']['SUPPORTS_TRANSACTIONS'] = connection.creation._rollback_works() except:
except:
# the database engine doesn't support transactions
pass pass


nose_argv = ['nosetests', '--verbosity', str(self.verbosity)] nose_argv = ['nosetests', '--verbosity', str(self.verbosity)]
Expand All @@ -78,6 +88,10 @@ def run_tests(self, test_labels, extra_tests=None):


result = self.run_suite(nose_argv) result = self.run_suite(nose_argv)


#Restore the old db name.
settings.DATABASES['default']['NAME'] = old_name
connection.settings_dict["DATABASE_NAME"] = old_name

self.teardown_test_environment() self.teardown_test_environment()
# suite_result expects the suite as the first argument. Fake it. # suite_result expects the suite as the first argument. Fake it.
return self.suite_result({}, result) return self.suite_result({}, result)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@
def read(filename): def read(filename):
return open(os.path.join(os.path.dirname(__file__), filename)).read() return open(os.path.join(os.path.dirname(__file__), filename)).read()


version = '0.3.0' version = '0.3.1'


setup( setup(
name='django_quick_test', name='django_quick_test',
Expand Down

0 comments on commit a53248b

Please sign in to comment.