#14296: 'manage.py test' failing for apps that access read-only databases
----------------------------------------+-----------------------------------
          Reporter:  kthhrv             |         Owner:  nobody
            Status:  new                |     Milestone:        
         Component:  Testing framework  |       Version:  1.2   
        Resolution:                     |      Keywords:        
             Stage:  Unreviewed         |     Has_patch:  0     
        Needs_docs:  0                  |   Needs_tests:  0     
Needs_better_patch:  0                  |  
----------------------------------------+-----------------------------------
Comment (by jonathan...@gmail.com):

 A simple hack that seems to work for this is to modify the action of
 setup_databases in django/test/simple.py

  def setup_databases(self, **kwargs):
         from django.db import connections
         old_names = []
         mirrors = []
         for alias in connections:
             connection = connections[alias]
 +           # If the alias name is contained within this setting,
 +           # just skip round the loop.
 +           # This causes all tests to occur against the aliased
 +           # connection, and not create a test db.
 +           try:
 +               if alias in settings.RUN_TESTS_ON_LIVE_DB:
 +                   continue
 +           except:
 +               pass

             # 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]
             else:

                 old_names.append((connection,
 connection.settings_dict['NAME']))
                 connection.creation.create_test_db(self.verbosity,
 autoclobber=not self.interactive)
         return old_names, mirrors

 and then place the names of the connections inside the variable in your
 settings.py:

     RUN_TESTS_ON_LIVE_DB = ['dbname',]

 This seems to force the tests to run against the live database, write
 operations will simply fail due to permissions and one no longer needs
 complex alternative db setups.

 Hack..

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14296#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to