Changeset 2940
- Timestamp:
- 05/18/06 13:25:49 (2 years ago)
- Files:
-
- django/trunk/tests/runtests.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/runtests.py
r2939 r2940 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 statements119 # 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: … … 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 … … 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__":
