Ticket #11635: testserver_backend.patch

File testserver_backend.patch, 3.3 KB (added by Nathaniel Whiteinge, 15 years ago)
  • django/test/utils.py

     
    8080    del mail.outbox
    8181
    8282
    83 def get_runner(settings):
    84     test_path = settings.TEST_RUNNER.split('.')
     83def get_runner(settings, wanted_method='TEST_RUNNER'):
     84    test_path = getattr(settings, wanted_method).split('.')
    8585    # Allow for Python 2.5 relative paths
    8686    if len(test_path) > 1:
    8787        test_module_name = '.'.join(test_path[:-1])
     
    9090    test_module = __import__(test_module_name, {}, {}, test_path[-1])
    9191    test_runner = getattr(test_module, test_path[-1])
    9292    return test_runner
     93
     94def get_create_test_db(settings):
     95    # Wrapper to deal with the strange way Django's core create_test_db is
     96    # created. There really must be a more elegant solution.
     97    if settings.TESTSERVER_DATABASE_CREATOR == 'django.db.connection.creation.create_test_db':
     98        from django.db import connection
     99        return connection.creation.create_test_db
     100    else:
     101        return get_runner(settings, wanted_method='TESTSERVER_DATABASE_CREATOR')
  • django/conf/global_settings.py

     
    381381# The name of the method to use to invoke the test suite
    382382TEST_RUNNER = 'django.test.simple.run_tests'
    383383
     384# The name of the method to create a test database for use with the
     385# testserver management command
     386TESTSERVER_DATABASE_CREATOR = 'django.db.connection.creation.create_test_db'
     387
    384388# The name of the database to use for testing purposes.
    385389# If None, a name of 'test_' + DATABASE_NAME will be assumed
    386390TEST_DATABASE_NAME = None
  • django/core/management/commands/testserver.py

     
    1515
    1616    def handle(self, *fixture_labels, **options):
    1717        from django.core.management import call_command
    18         from django.db import connection
     18        from django.conf import settings
     19        from django.test.utils import get_create_test_db
    1920
    2021        verbosity = int(options.get('verbosity', 1))
    2122        addrport = options.get('addrport')
    2223
    2324        # Create a test database.
    24         db_name = connection.creation.create_test_db(verbosity=verbosity)
     25        create_test_db = get_create_test_db(settings)
     26        db_name = create_test_db(verbosity=verbosity)
    2527
    2628        # Import the fixture data into the test database.
    2729        call_command('loaddata', *fixture_labels, **{'verbosity': verbosity})
  • docs/ref/settings.txt

     
    11101110
    11111111.. _Testing Django Applications: ../testing/
    11121112
     1113.. setting:: TESTSERVER_DATABASE_CREATOR
     1114
     1115TESTSERVER_DATABASE_CREATOR
     1116---------------------------
     1117
     1118Default: ``'django.db.connection.creation.create_test_db'``
     1119
     1120The name of the method to use to create the database used by the
     1121:ref:`testserver` management command.
     1122
    11131123.. setting:: TIME_FORMAT
    11141124
    11151125TIME_FORMAT
Back to Top