Always asks about deleting an SQLite database file specified in TEST_NAME
See original GitHub issueWhen specifying an on-disk SQLite database in the TEST_NAME
database setting, django-nose always asks if the user wants to try deleting it, even if there was no such file.
To reproduce, install django-nose 7fd0132090256e752119f90a3d4568203c486f2e and create a new Django project with django-admin.py startproject
. Do these changes to settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/tmp/db.sqlite',
'TEST_NAME': '/tmp/test.sqlite'
}
}
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
INSTALLED_APPS = (
# ...
'django_nose',
# ...
}
Run the tests:
$ rm -f /tmp/db.sqlite /tmp/test.sqlite
$ ./manage.py test
nosetests --verbosity=1
Creating test database for alias 'default'...
Destroying old test database 'default'...
Type 'yes' if you would like to try deleting the test database '/tmp/test.sqlite', or 'no' to cancel: yes
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
The reason for this behavior seems to be in django_nose.runner._should_create_database()
. The connection.cursor()
line creates a zero-length SQLite file, and later django.db.backends.sqlite3.creation.DatabaseCreation._create_test_db()
finds it and suggests deleting it.
If TEST_NAME
is not specified and Django’s default mechanism for generating the test database name is used, everything works as expected.
Issue Analytics
- State:
- Created 11 years ago
- Comments:5 (2 by maintainers)
This issue is still present in django_nose 1.2. A workaround for me is using --noinput as option for the manage.py test command.
I’m running into this using Django 1.10.5 and django-nose 1.4.4.
I’ve traced it down to runner.py in _should_create_database(connection) where it does “connection.cursor()”. The sqlite file doesn’t exist before that call and does afterwards.