Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got an error creating the test database: Django unittest

When I run python manage.py test, django is asking a strange question each time:

$ python manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: (1044, "Access denied for user 'nyble'@'localhost' to database 'test_nybledb'")
Type 'yes' if you would like to try deleting the test database 'test_nybledb', or 'no' to cancel: 

I was expecting it to just delete and remake a basic sqlite3 DB, and I don't want this behavior.

Whether I say yes or no it just exits tests:

Destroying old test database for alias 'default'...
Got an error recreating the test database: (1044, "Access denied for user 'nyble'@'localhost' to database 'test_nybledb'")

In settings I have

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'nybledb',
        'USER': 'nyble',
        'PASSWORD': 'password',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

How can I stop this and make it use normal sqlite3 db during running tests?

like image 925
codyc4321 Avatar asked Nov 24 '17 04:11

codyc4321


1 Answers

You can set this up in settings.py. It says that if there is 'test' in the command line input, use sqlite as db engine.

import sys
if 'test' in sys.argv or 'test_coverage' in sys.argv: #Covers regular testing and django-coverage
    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
like image 171
kawadhiya21 Avatar answered Nov 16 '22 12:11

kawadhiya21