Browse files

Refs #2333 - Added a TEST_DATABASE_NAME setting that can be used to o…

…verride the 'test_' + DATABASE_NAME naming policy. This setting is then used in to restore the use of 'django_test_db' as the Django model/regression test database. Thanks to Michael Radziej for the feedback.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 60ebb61 commit d78e2ae3557feb1c9374cc56f6c130b13a7ef789 @freakboy3742 freakboy3742 committed Sep 1, 2006
Showing with 39 additions and 12 deletions.
  1. +6 −1 django/conf/
  2. +4 −1 django/test/
  3. +12 −0 docs/settings.txt
  4. +10 −7 docs/testing.txt
  5. +7 −3 tests/
@@ -301,4 +301,9 @@
+# The name of the method to use to invoke the test suite
+TEST_RUNNER = 'django.test.simple.run_tests'
+# The name of the database to use for testing purposes.
+# If None, a name of 'test_' + DATABASE_NAME will be assumed
@@ -21,7 +21,10 @@ def create_test_db(verbosity=1, autoclobber=False):
if settings.DATABASE_ENGINE == "sqlite3":
+ if settings.TEST_DATABASE_NAME:
+ else:
# Create the test database and connect to it. We need to autocommit
# if the database supports it because PostgreSQL doesn't allow
@@ -766,6 +766,18 @@ The name of the method to use for starting the test suite. See
.. _Testing Django Applications: ../testing/
+**New in Django development version**
+Default: ``None``
+The name of database to use when running the test suite. If a value of
+``None`` is specified, the test database will use the name ``'test_' + settings.DATABASE_NAME``. See `Testing Django Applications`_.
+.. _Testing Django Applications: ../testing/
@@ -8,7 +8,7 @@ Automated testing is an extremely useful weapon in the bug-killing arsenal
of the modern developer. When initially writing code, a test suite can be
used to validate that code behaves as expected. When refactoring or
modifying code, tests serve as a guide to ensure that behavior hasn't
-changed as a result of the refactor.
+changed unexpectedly as a result of the refactor.
Testing an web application is a complex task, as there are many
components of a web application that must be validated and tested. To
@@ -189,10 +189,13 @@ but you only want to run the animals unit tests, run::
When you run your tests, you'll see a bunch of text flow by as the test
database is created and models are initialized. This test database is
-created from scratch every time you run your tests. The test database
-gets its name by prepending ``test_`` to the database name specified by
-``settings.DATABASE_NAME``; all other database settings will the same as
-they would be for the project normally.
+created from scratch every time you run your tests.
+By default, the test database gets its name by prepending ``test_`` to
+the database name specified by the ``DATABASE_NAME`` setting; all other
+database settings will the same as they would be for the project normally.
+If you wish to use a name other than the default for the test database,
+you can use the ``TEST_DATABASE_NAME`` setting to provide a name.
Once the test database has been established, Django will run your tests.
If everything goes well, at the end you'll see::
@@ -265,8 +268,8 @@ arguments:
The module list is the list of Python modules that contain the models to be
tested. This is the same format returned by ``django.db.models.get_apps()``
-Verbosity determines the amount of debug information that will be
-provided to the console; '0' is no output, '1' is normal output,
+Verbosity determines the amount of notification and debug information that
+will be printed to the console; '0' is no output, '1' is normal output,
and `2` is verbose output.
Testing utilities
@@ -5,6 +5,7 @@
MODEL_TESTS_DIR_NAME = 'modeltests'
REGRESSION_TESTS_DIR_NAME = 'regressiontests'
+TEST_DATABASE_NAME = 'django_test_db'
MODEL_TEST_DIR = os.path.join(os.path.dirname(__file__), MODEL_TESTS_DIR_NAME)
REGRESSION_TEST_DIR = os.path.join(os.path.dirname(__file__), REGRESSION_TESTS_DIR_NAME)
@@ -71,9 +72,12 @@ def django_tests(verbosity, tests_to_run):
from django.conf import settings
from django.db.models.loading import get_apps, load_app
old_installed_apps = settings.INSTALLED_APPS
+ old_test_database_name = settings.TEST_DATABASE_NAME
- # load all the ALWAYS_INSTALLED_APPS
+ # load all the ALWAYS_INSTALLED_APPS
test_models = []
@@ -105,9 +109,9 @@ def django_tests(verbosity, tests_to_run):
from django.test.simple import run_tests
run_tests(test_models, verbosity, extra_tests=extra_tests)
- # Restore the old INSTALLED_APPS setting
+ # Restore the old settings
settings.INSTALLED_APPS = old_installed_apps
+ settings.TESTS_DATABASE_NAME = old_test_database_name
if __name__ == "__main__":
from optparse import OptionParser
usage = "%prog [options] [model model model ...]"

0 comments on commit d78e2ae

Please sign in to comment.