diff -r 41150ab49bb8 django/db/backends/creation.py
|
a
|
b
|
|
| 19 | 19 | |
| 20 | 20 | def __init__(self, connection): |
| 21 | 21 | self.connection = connection |
| | 22 | self.test_database_name = None |
| 22 | 23 | |
| 23 | 24 | def _digest(self, *args): |
| 24 | 25 | """ |
| … |
… |
|
| 343 | 344 | if verbosity >= 1: |
| 344 | 345 | print "Creating test database '%s'..." % self.connection.alias |
| 345 | 346 | |
| 346 | | test_database_name = self._create_test_db(verbosity, autoclobber) |
| | 347 | self.test_database_name = self._create_test_db(verbosity, autoclobber) |
| 347 | 348 | |
| 348 | 349 | self.connection.close() |
| 349 | | self.connection.settings_dict["NAME"] = test_database_name |
| | 350 | self.connection.settings_dict['NAME'] = self.test_database_name |
| 350 | 351 | |
| 351 | 352 | # Confirm the feature set of the test database |
| 352 | 353 | self.connection.features.confirm() |
| … |
… |
|
| 367 | 368 | # the side effect of initializing the test database. |
| 368 | 369 | cursor = self.connection.cursor() |
| 369 | 370 | |
| 370 | | return test_database_name |
| | 371 | return self.test_database_name |
| 371 | 372 | |
| 372 | 373 | def _create_test_db(self, verbosity, autoclobber): |
| 373 | 374 | "Internal implementation - creates the test db tables." |
| … |
… |
|
| 414 | 415 | if verbosity >= 1: |
| 415 | 416 | print "Destroying test database '%s'..." % self.connection.alias |
| 416 | 417 | self.connection.close() |
| 417 | | test_database_name = self.connection.settings_dict['NAME'] |
| | 418 | test_database_name = self.test_database_name |
| 418 | 419 | self.connection.settings_dict['NAME'] = old_database_name |
| 419 | 420 | |
| 420 | 421 | self._destroy_test_db(test_database_name, verbosity) |
| … |
… |
|
| 428 | 429 | cursor = self.connection.cursor() |
| 429 | 430 | self.set_autocommit() |
| 430 | 431 | time.sleep(1) # To avoid "database is being accessed by other users" errors. |
| 431 | | cursor.execute("DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name)) |
| | 432 | cursor.execute("DROP DATABASE IF EXISTS %s" % self.connection.ops.quote_name(test_database_name)) |
| 432 | 433 | self.connection.close() |
| 433 | 434 | |
| 434 | 435 | def set_autocommit(self): |
diff -r 41150ab49bb8 django/db/backends/sqlite3/creation.py
|
a
|
b
|
|
| 61 | 61 | return test_database_name |
| 62 | 62 | |
| 63 | 63 | def _destroy_test_db(self, test_database_name, verbosity): |
| 64 | | if test_database_name and test_database_name != ":memory:": |
| | 64 | if test_database_name and test_database_name != ":memory:" and os.access(test_database_name, os.F_OK): |
| 65 | 65 | # Remove the SQLite database file |
| 66 | 66 | os.remove(test_database_name) |