I use django nose to run my unit tests in django (1.4).
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Creating a database takes a lot of time.
So, I found myself putting this in settings.py:
os.environ['REUSE_DB'] = "1"
gotta do the trick.
django itsellve actually gives this suggestion:
To reuse old database "<path not very interesting>/var/sqlite/unittest.db" for speed, set env var REUSE_DB=1.
Of course, you need to run it once (or after each database change) using this flag = 0
However, when you set the flag to 0, my tests end up with a remark:
Destroying test database for alias 'default'...
So when I want to run it with reuse ... there is nothing to reuse ... and I will get errors saying that the table does not exist
DatabaseError: no such table: <and than a table name>
The test runs fine if reuse_db is set to 0
I use the test database alias in my development settings:
DATABASES = { 'default': { 'NAME': os.path.join(BUILDOUT_DIR, 'var', 'sqlite', 'development.db'), 'TEST_NAME': os.path.join(BUILDOUT_DIR, 'var', 'sqlite', 'unittest.db'), 'ENGINE': 'django.db.backends.sqlite3', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } }
I do not use the sqlite database in memory for testing, because I read that this does not work with django-nose.
So how can I reuse the database when it destroys the database at the end ...
according to this https://docs.djangoproject.com/en/1.4/topics/testing/#the-test-database django does this, but it does not show how to prevent it (if possible), or how to use the option reuse_db. use other settings?