mirror of
https://github.com/django/django.git
synced 2025-06-06 20:19:13 +00:00
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:
parent
9e64035796
commit
f6e75ab3cf
@ -51,6 +51,11 @@ class TestRunner:
|
|||||||
# Manually set INSTALLED_APPS to point to the test app.
|
# Manually set INSTALLED_APPS to point to the test app.
|
||||||
settings.INSTALLED_APPS = (APP_NAME,)
|
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
|
# Create the test database and connect to it. We need autocommit() because
|
||||||
# PostgreSQL doesn't allow CREATE DATABASE statements within transactions.
|
# PostgreSQL doesn't allow CREATE DATABASE statements within transactions.
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
@ -101,9 +106,11 @@ class TestRunner:
|
|||||||
self.output(1, "%s model: Running tests" % model_name)
|
self.output(1, "%s model: Running tests" % model_name)
|
||||||
runner.run(dtest, clear_globs=True, out=sys.stdout.write)
|
runner.run(dtest, clear_globs=True, out=sys.stdout.write)
|
||||||
|
|
||||||
# Remove the test database, to clean up after ourselves. Connect to the
|
# Unless we're using SQLite, remove the test database, to clean up after
|
||||||
# previous database (not the test database) to do so, because it's not
|
# ourselves. Connect to the previous database (not the test database)
|
||||||
# allowed to delete a database while being connected to it.
|
# to do so, because it's not allowed to delete a database while being
|
||||||
|
# connected to it.
|
||||||
|
if settings.DATABASE_ENGINE != "sqlite3":
|
||||||
db.close()
|
db.close()
|
||||||
settings.DATABASE_NAME = old_database_name
|
settings.DATABASE_NAME = old_database_name
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user