M
M
maxclax2015-04-05 21:22:05
Django
maxclax, 2015-04-05 21:22:05

How to change the database for tests?

The manual says that when testing an application, a new database is created and everything goes through it. After passing the tests, it is deleted. But in my case, all tests on the main database pass. After the test, there are new records in the main database. What is the reason for this phenomenon?

# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

I use the models in the tests through Factory Boy. But it doesn't really matter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2015-04-05
@maxclax

Hello. Create a separate settings.py for tests and run on it. Another tip: use in-memory sqlite - many times faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question