django-nose icon indicating copy to clipboard operation
django-nose copied to clipboard

Always asks about deleting an SQLite database file specified in TEST_NAME

Open akaihola opened this issue 12 years ago • 5 comments

When 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.

akaihola avatar Sep 19 '12 08:09 akaihola

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.

sterago avatar Jul 30 '14 07:07 sterago

Does this still happen in django-nose 1.4?

jwhitlock avatar Jul 03 '15 03:07 jwhitlock

Unfortunately it still happens, I just reproduced the issue using django_nose 1.4.1 and nose 1.3.7

sterago avatar Jul 03 '15 07:07 sterago

Thanks for checking. Django 1.7 improved database setup in 1.7, we may be able to lean on that code or learn from them.

jwhitlock avatar Jul 04 '15 14:07 jwhitlock

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.

kellycampbell avatar Jan 11 '17 21:01 kellycampbell