Ticket #6134: sqlitetest.patch
File sqlitetest.patch, 3.2 KB (added by , 17 years ago) |
---|
-
django/test/utils.py
1 import sys, time 1 import sys, time, os 2 2 from django.conf import settings 3 3 from django.db import connection, get_creation_module 4 4 from django.core import mail … … 106 106 if verbosity >= 1: 107 107 print "Creating test database..." 108 108 # If we're using SQLite, it's more convenient to test against an 109 # in-memory database. 109 # in-memory database. Using the TEST_DATABASE_NAME setting you can still choose 110 # to run on a physical database. 110 111 if settings.DATABASE_ENGINE == "sqlite3": 111 TEST_DATABASE_NAME = ":memory:" 112 if settings.TEST_DATABASE_NAME and settings.TEST_DATABASE_NAME != ":memory:": 113 TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME 114 # Erase the old test database 115 if verbosity >= 1: 116 print "Destroying old test database..." 117 if os.access(TEST_DATABASE_NAME, os.F_OK): 118 if not autoclobber: 119 confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % TEST_DATABASE_NAME) 120 if autoclobber or confirm == 'yes': 121 try: 122 if verbosity >= 1: 123 print "Destroying old test database..." 124 os.remove(TEST_DATABASE_NAME) 125 except Exception, e: 126 sys.stderr.write("Got an error deleting the old test database: %s\n" % e) 127 sys.exit(2) 128 else: 129 print "Tests cancelled." 130 sys.exit(1) 131 if verbosity >= 1: 132 print "Creating test database..." 133 else: 134 TEST_DATABASE_NAME = ":memory:" 112 135 else: 113 136 suffix = { 114 137 'postgresql': get_postgresql_create_suffix, … … 171 194 creation_module.destroy_test_db(settings, connection, old_database_name, verbosity) 172 195 return 173 196 174 # Unless we're using SQLite, remove the test database to clean up after175 # ourselves. Connect to the previous database (not the test database)176 # to do so, because it's not allowed to delete a database while being177 # connected to it.178 197 if verbosity >= 1: 179 198 print "Destroying test database..." 180 199 connection.close() 181 200 TEST_DATABASE_NAME = settings.DATABASE_NAME 182 201 settings.DATABASE_NAME = old_database_name 183 184 if settings.DATABASE_ENGINE != "sqlite3": 202 if settings.DATABASE_ENGINE == "sqlite3": 203 if TEST_DATABASE_NAME and TEST_DATABASE_NAME != ":memory:": 204 # Remove the SQLite database file 205 os.remove(TEST_DATABASE_NAME) 206 else: 207 # Remove the test database to clean up after 208 # ourselves. Connect to the previous database (not the test database) 209 # to do so, because it's not allowed to delete a database while being 210 # connected to it. 185 211 cursor = connection.cursor() 186 212 _set_autocommit(connection) 187 213 time.sleep(1) # To avoid "database is being accessed by other users" errors.