Added support for sqlite backend to test framework

git-svn-id: http://code.djangoproject.com/svn/django/trunk@341 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2005-07-29 19:22:50 +00:00
parent 9e64035796
commit f6e75ab3cf
1 changed files with 38 additions and 31 deletions

View File

@ -51,6 +51,11 @@ class TestRunner:
# Manually set INSTALLED_APPS to point to the test app.
settings.INSTALLED_APPS = (APP_NAME,)
# If we're using SQLite, it's more convient to test against an in-memory database
if settings.DATABASE_ENGINE == "sqlite3":
global TEST_DATABASE_NAME
TEST_DATABASE_NAME = ":memory:"
else:
# Create the test database and connect to it. We need autocommit() because
# PostgreSQL doesn't allow CREATE DATABASE statements within transactions.
cursor = db.cursor()
@ -101,9 +106,11 @@ class TestRunner:
self.output(1, "%s model: Running tests" % model_name)
runner.run(dtest, clear_globs=True, out=sys.stdout.write)
# Remove the test database, to clean up after ourselves. Connect to the
# previous database (not the test database) to do so, because it's not
# allowed to delete a database while being connected to it.
# Unless we're using SQLite, remove the test database, to clean up after
# ourselves. Connect to the previous database (not the test database)
# to do so, because it's not allowed to delete a database while being
# connected to it.
if settings.DATABASE_ENGINE != "sqlite3":
db.close()
settings.DATABASE_NAME = old_database_name
cursor = db.cursor()