The tests now run correctly with the new psycopg2 backend. There's 4 failures, but they all have to do with the new way the psycopg2 handles datetimes and are probably a single fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2940 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2006-05-18 18:25:49 +00:00
parent 5a8ed6f7f6
commit e6ee971498
1 changed files with 15 additions and 13 deletions

View File

@ -114,14 +114,11 @@ class TestRunner:
global TEST_DATABASE_NAME global TEST_DATABASE_NAME
TEST_DATABASE_NAME = ":memory:" TEST_DATABASE_NAME = ":memory:"
else: else:
# Create the test database and connect to it. We need autocommit() # Create the test database and connect to it. We need to autocommit
# because PostgreSQL doesn't allow CREATE DATABASE statements # if the database supports it because PostgreSQL doesn't allow
# within transactions. # CREATE/DROP DATABASE statements within transactions.
cursor = connection.cursor() cursor = connection.cursor()
try: self._set_autocommit(connection)
connection.connection.autocommit(1)
except AttributeError:
pass
self.output(1, "Creating test database") self.output(1, "Creating test database")
try: try:
cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME) cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME)
@ -224,11 +221,7 @@ class TestRunner:
settings.DATABASE_NAME = old_database_name settings.DATABASE_NAME = old_database_name
cursor = connection.cursor() cursor = connection.cursor()
self.output(1, "Deleting test database") self.output(1, "Deleting test database")
try: self._set_autocommit(connection)
connection.connection.autocommit(1)
except AttributeError:
pass
else:
time.sleep(1) # To avoid "database is being accessed by other users" errors. time.sleep(1) # To avoid "database is being accessed by other users" errors.
cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME) cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME)
@ -243,6 +236,15 @@ class TestRunner:
else: else:
print "All tests passed." print "All tests passed."
def _set_autocommit(self, connection):
"""
Make sure a connection is in autocommit mode.
"""
if hasattr(connection.connection, "autocommit"):
connection.connection.autocommit(True)
elif hasattr(connection.connection, "set_isolation_level"):
connection.connection.set_isolation_level(0)
if __name__ == "__main__": if __name__ == "__main__":
from optparse import OptionParser from optparse import OptionParser
usage = "%prog [options] [model model model ...]" usage = "%prog [options] [model model model ...]"