Permalink
Browse files

Don't prompt the user to pass REUSE_DB when doing so makes no sense.

For example, when he already passed the option or when using an in-memory SQLite DB.
  • Loading branch information...
1 parent 84c9e11 commit e976b6b2f9091f5ad6a6a2da54a25104a137c439 @erikrose erikrose committed Mar 13, 2012
Showing with 11 additions and 6 deletions.
  1. +11 −6 django_nose/runner.py
View
@@ -220,6 +220,12 @@ class NoseTestSuiteRunner(BasicNoseRunner):
"""
def setup_databases(self):
+ def can_support_reuse_db(connection):
+ """Return whether it makes any sense to use REUSE_DB with the backend of a connection."""
+ # This is a SQLite in-memory DB. Those are created implicitly when
+ # you try to connect to them, so our test below doesn't work.
+ return not connection.creation._get_test_db_name() == ':memory:'
+
def should_create_database(connection):
"""Return whether we should recreate the given DB.
@@ -233,10 +239,7 @@ def should_create_database(connection):
# faster way, I'm inclined to keep making people explicitly saying
# REUSE_DB if they want to reuse the DB.
- if connection.creation._get_test_db_name() == ':memory:':
- # This is a SQLite in-memory DB. Those are created implicitly
- # when you try to connect to them, so our test below doesn't
- # work.
+ if not can_support_reuse_db(connection):
return True
# Notice whether the DB exists, and create it if it doesn't:
@@ -274,9 +277,11 @@ def mysql_reset_sequences(style, connection):
orig_db_name = connection.settings_dict['NAME']
connection.settings_dict['NAME'] = test_db_name
- if should_create_database(connection):
+ if not _reusing_db() and can_support_reuse_db(connection):
print ('To reuse old database "%s" for speed, set env var '
- 'REUSE_DB=1' % test_db_name)
+ 'REUSE_DB=1.' % test_db_name)
+
+ if should_create_database(connection):
# We're not using skip_create_test_db, so put the DB name back:
connection.settings_dict['NAME'] = orig_db_name
else:

0 comments on commit e976b6b

Please sign in to comment.