Django

Code

Changeset 3706

Show
Ignore:
Timestamp:
09/01/06 08:33:26 (2 years ago)
Author:
russellm
Message:

Refs #2333 - Added a TEST_DATABASE_NAME setting that can be used to override the 'test_' + DATABASE_NAME naming policy. This setting is then used in runtests.py to restore the use of 'django_test_db' as the Django model/regression test database. Thanks to Michael Radziej for the feedback.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/conf/global_settings.py

    r3660 r3706  
    302302########### 
    303303 
    304 TEST_RUNNER='django.test.simple.run_tests' 
     304# The name of the method to use to invoke the test suite 
     305TEST_RUNNER = 'django.test.simple.run_tests' 
     306 
     307# The name of the database to use for testing purposes. 
     308# If None, a name of 'test_' + DATABASE_NAME will be assumed 
     309TEST_DATABASE_NAME = None 
  • django/trunk/django/test/utils.py

    r3689 r3706  
    2222        TEST_DATABASE_NAME = ":memory:" 
    2323    else: 
    24         TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME 
     24        if settings.TEST_DATABASE_NAME: 
     25            TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME 
     26        else: 
     27            TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME 
    2528         
    2629        # Create the test database and connect to it. We need to autocommit 
  • django/trunk/docs/settings.txt

    r3689 r3706  
    767767.. _Testing Django Applications: ../testing/ 
    768768 
     769TEST_DATABASE_NAME 
     770------------------ 
     771 
     772**New in Django development version** 
     773 
     774Default: ``None`` 
     775 
     776The name of database to use when running the test suite. If a value of  
     777``None`` is specified, the test database will use the name ``'test_' + settings.DATABASE_NAME``. See `Testing Django Applications`_. 
     778 
     779.. _Testing Django Applications: ../testing/ 
     780 
    769781TIME_FORMAT 
    770782----------- 
  • django/trunk/docs/testing.txt

    r3689 r3706  
    99used to validate that code behaves as expected. When refactoring or 
    1010modifying code, tests serve as a guide to ensure that behavior hasn't 
    11 changed as a result of the refactor. 
     11changed unexpectedly as a result of the refactor. 
    1212 
    1313Testing an web application is a complex task, as there are many 
     
    190190When you run your tests, you'll see a bunch of text flow by as the test 
    191191database is created and models are initialized. This test database is 
    192 created from scratch every time you run your tests. The test database 
    193 gets its name by prepending ``test_`` to the database name specified by 
    194 ``settings.DATABASE_NAME``; all other database settings will the same as 
    195 they would be for the project normally. 
     192created from scratch every time you run your tests.  
     193 
     194By default, the test database gets its name by prepending ``test_`` to  
     195the database name specified by the ``DATABASE_NAME`` setting; all other  
     196database settings will the same as they would be for the project normally. 
     197If you wish to use a name other than the default for the test database,  
     198you can use the ``TEST_DATABASE_NAME`` setting to provide a name.  
    196199 
    197200Once the test database has been established, Django will run your tests. 
     
    266269tested. This is the same format returned by ``django.db.models.get_apps()`` 
    267270 
    268 Verbosity determines the amount of debug information that will be 
    269 provided to the console; '0' is no output, '1' is normal output, 
     271Verbosity determines the amount of notification and debug information that  
     272will be printed to the console; '0' is no output, '1' is normal output, 
    270273and `2` is verbose output. 
    271274 
  • django/trunk/tests/runtests.py

    r3661 r3706  
    66MODEL_TESTS_DIR_NAME = 'modeltests' 
    77REGRESSION_TESTS_DIR_NAME = 'regressiontests' 
     8TEST_DATABASE_NAME = 'django_test_db' 
    89 
    910MODEL_TEST_DIR = os.path.join(os.path.dirname(__file__), MODEL_TESTS_DIR_NAME) 
     
    7273    from django.db.models.loading import get_apps, load_app 
    7374    old_installed_apps = settings.INSTALLED_APPS 
     75    old_test_database_name = settings.TEST_DATABASE_NAME 
    7476     
     77    settings.TEST_DATABASE_NAME = TEST_DATABASE_NAME 
     78    settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS 
     79 
    7580    # load all the ALWAYS_INSTALLED_APPS 
    76     settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS 
    7781    get_apps() 
    7882     
     
    106110    run_tests(test_models, verbosity, extra_tests=extra_tests) 
    107111   
    108     # Restore the old INSTALLED_APPS setting 
     112    # Restore the old settings 
    109113    settings.INSTALLED_APPS = old_installed_apps 
    110        
     114    settings.TESTS_DATABASE_NAME = old_test_database_name 
    111115if __name__ == "__main__": 
    112116    from optparse import OptionParser