From 41e73de39df31c4b13d65462bfeedde6924226d8 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 12 Jul 2018 00:14:24 -0400 Subject: Fixed #28478 -- Make DiscoverRunner skip creating unused test databases. SimpleTestCase.databases makes it possible to determine the set of databases required to run the discovered tests. --- docs/releases/2.2.txt | 3 +++ docs/topics/testing/advanced.txt | 10 +++++++++- docs/topics/testing/tools.txt | 15 ++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'docs') diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index 5c488570aa..4a529f30da 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -293,6 +293,9 @@ Tests for older versions of SQLite because they would require expensive table introspection there. +* :class:`~django.test.runner.DiscoverRunner` now skips the setup of databases + not :ref:`referenced by tests`. + URLs ~~~~ diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt index a3112fb367..0a228fc4ef 100644 --- a/docs/topics/testing/advanced.txt +++ b/docs/topics/testing/advanced.txt @@ -614,7 +614,7 @@ utility methods in the ``django.test.utils`` module. Performs global post-test teardown, such as removing instrumentation from the template system and restoring normal email services. -.. function:: setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, parallel=0, **kwargs) +.. function:: setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, parallel=0, aliases=None, **kwargs) Creates the test databases. @@ -622,6 +622,14 @@ utility methods in the ``django.test.utils`` module. that have been made. This data will be provided to the :func:`teardown_databases` function at the conclusion of testing. + The ``aliases`` argument determines which :setting:`DATABASES` aliases test + databases should be setup for. If it's not provided, it defaults to all of + :setting:`DATABASES` aliases. + + .. versionadded:: 2.2 + + The ``aliases`` argument was added. + .. function:: teardown_databases(old_config, parallel=0, keepdb=False) Destroys the test databases, restoring pre-test conditions. diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 12f20c0144..e656f89124 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -1134,13 +1134,14 @@ Multi-database support .. versionadded:: 2.2 Django sets up a test database corresponding to every database that is -defined in the :setting:`DATABASES` definition in your settings -file. However, a big part of the time taken to run a Django TestCase -is consumed by the call to ``flush`` that ensures that you have a -clean database at the start of each test run. If you have multiple -databases, multiple flushes are required (one for each database), -which can be a time consuming activity -- especially if your tests -don't need to test multi-database activity. +defined in the :setting:`DATABASES` definition in your settings and referred to +by at least one test through ``databases``. + +However, a big part of the time taken to run a Django ``TestCase`` is consumed +by the call to ``flush`` that ensures that you have a clean database at the +start of each test run. If you have multiple databases, multiple flushes are +required (one for each database), which can be a time consuming activity -- +especially if your tests don't need to test multi-database activity. As an optimization, Django only flushes the ``default`` database at the start of each test run. If your setup contains multiple databases, -- cgit v1.3