jazzband / django-nose

Django test runner using nose
http://pypi.python.org/pypi/django-nose
BSD 3-Clause "New" or "Revised" License
881 stars 239 forks source link

Always asks about deleting an SQLite database file specified in TEST_NAME #97

Open akaihola opened 12 years ago

akaihola commented 12 years ago

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.

sterago commented 10 years ago

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.

jwhitlock commented 9 years ago

Does this still happen in django-nose 1.4?

sterago commented 9 years ago

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

jwhitlock commented 9 years ago

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.

kellycampbell commented 7 years ago

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.