Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit e6ee9714983c7245747213a2a1d127070745c0ad 1 parent 5a8ed6f
Jacob Kaplan-Moss authored May 18, 2006

Showing 1 changed file with 15 additions and 13 deletions. Show diff stats Hide diff stats

  1. 28  tests/runtests.py
28  tests/runtests.py
@@ -114,14 +114,11 @@ def run_tests(self):
114 114
             global TEST_DATABASE_NAME
115 115
             TEST_DATABASE_NAME = ":memory:"
116 116
         else:
117  
-            # Create the test database and connect to it. We need autocommit()
118  
-            # because PostgreSQL doesn't allow CREATE DATABASE statements
119  
-            # within transactions.
  117
+            # Create the test database and connect to it. We need to autocommit
  118
+            # if the database supports it because PostgreSQL doesn't allow 
  119
+            # CREATE/DROP DATABASE statements within transactions.
120 120
             cursor = connection.cursor()
121  
-            try:
122  
-                connection.connection.autocommit(1)
123  
-            except AttributeError:
124  
-                pass
  121
+            self._set_autocommit(connection)
125 122
             self.output(1, "Creating test database")
126 123
             try:
127 124
                 cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME)
@@ -224,12 +221,8 @@ def run_tests(self):
224 221
             settings.DATABASE_NAME = old_database_name
225 222
             cursor = connection.cursor()
226 223
             self.output(1, "Deleting test database")
227  
-            try:
228  
-                connection.connection.autocommit(1)
229  
-            except AttributeError:
230  
-                pass
231  
-            else:
232  
-                time.sleep(1) # To avoid "database is being accessed by other users" errors.
  224
+            self._set_autocommit(connection)
  225
+            time.sleep(1) # To avoid "database is being accessed by other users" errors.
233 226
             cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME)
234 227
 
235 228
         # Display output.
@@ -242,6 +235,15 @@ def run_tests(self):
242 235
             print "%s error%s:" % (len(error_list), len(error_list) != 1 and 's' or '')
243 236
         else:
244 237
             print "All tests passed."
  238
+            
  239
+    def _set_autocommit(self, connection):
  240
+        """
  241
+        Make sure a connection is in autocommit mode.
  242
+        """
  243
+        if hasattr(connection.connection, "autocommit"):
  244
+            connection.connection.autocommit(True)
  245
+        elif hasattr(connection.connection, "set_isolation_level"):
  246
+            connection.connection.set_isolation_level(0)
245 247
 
246 248
 if __name__ == "__main__":
247 249
     from optparse import OptionParser

0 notes on commit e6ee971

Please sign in to comment.
Something went wrong with that request. Please try again.