Got an error creating the test database: Django unittest
Asked Answered
R

1

6

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?

Rothberg answered 24/11, 2017 at 4:0 Comment(0)
D
10

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'
Dylandylana answered 24/11, 2017 at 4:5 Comment(1)
thanks you this is very useful.you just saved me.God bless You )))Bulimia

© 2022 - 2024 — McMap. All rights reserved.