Skip to content

Commit

Permalink
Tweaked order of create_test_db arguments for backwards compatibility.
Browse files Browse the repository at this point in the history
Since `serialize` was backported to 1.7, it should appear before `keepdb`.
  • Loading branch information
timgraham committed Jun 9, 2014
1 parent 67ce2e7 commit 3a926c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion django/db/backends/creation.py
Expand Up @@ -337,7 +337,7 @@ def sql_destroy_indexes_for_fields(self, model, fields, style):
";",
]

def create_test_db(self, verbosity=1, autoclobber=False, keepdb=False, serialize=True):
def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb=False):
"""
Creates a test database, prompting the user for confirmation if the
database already exists. Returns the name of the test database created.
Expand Down Expand Up @@ -419,6 +419,7 @@ def serialize_db_to_string(self):
app_config.name not in settings.TEST_NON_SERIALIZED_APPS
):
app_list.append((app_config, None))

# Make a function to iteratively return every object
def get_objects():
for model in sort_dependencies(app_list):
Expand Down
26 changes: 19 additions & 7 deletions docs/topics/testing/advanced.txt
Expand Up @@ -485,7 +485,7 @@ django.db.connection.creation
The creation module of the database backend also provides some utilities that
can be useful during testing.

.. function:: create_test_db([verbosity=1, autoclobber=False, keepdb=False, serialize=True])
.. function:: create_test_db([verbosity=1, autoclobber=False, serialize=True, keepdb=False])

Creates a new test database and runs ``migrate`` against it.

Expand All @@ -501,24 +501,32 @@ can be useful during testing.
* If autoclobber is ``True``, the database will be destroyed
without consulting the user.

``keepdb`` determines if the test run should use an existing
database, or create a new one. If ``True``, the existing
database will be used, or created if not present. If ``False``,
a new database will be created, prompting the user to remove
the existing one, if present.

``serialize`` determines if Django serializes the database into an
in-memory JSON string before running tests (used to restore the database
state between tests if you don't have transactions). You can set this to
False to significantly speed up creation time if you know you don't need
data persistance outside of test fixtures.

``keepdb`` determines if the test run should use an existing
database, or create a new one. If ``True``, the existing
database will be used, or created if not present. If ``False``,
a new database will be created, prompting the user to remove
the existing one, if present.

Returns the name of the test database that it created.

``create_test_db()`` has the side effect of modifying the value of
:setting:`NAME` in :setting:`DATABASES` to match the name of the test
database.

.. versionchanged:: 1.7

The ``serialize`` argument was added.

.. versionchanged:: 1.8

The ``keepdb`` argument was added.

.. function:: destroy_test_db(old_database_name, [verbosity=1, keepdb=False])

Destroys the database whose name is the value of :setting:`NAME` in
Expand All @@ -531,6 +539,10 @@ can be useful during testing.
If the ``keepdb`` argument is ``True``, then the connection to the
database will be closed, but the database will not be destroyed.

.. versionchanged:: 1.8

The ``keepdb`` argument was added.

.. _topics-testing-code-coverage:

Integration with coverage.py
Expand Down

0 comments on commit 3a926c0

Please sign in to comment.