Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running django tests with sqlite

I use Postgres for production and development, but I'd like to use sqlite to run some tests. I don't see an easy way to configure one engine for tests and another for dev / production. Am I missing something?

like image 591
jMyles Avatar asked Jun 15 '11 04:06

jMyles


People also ask

Can you use SQLite with Django?

By default, the configuration uses SQLite. If you're new to databases, or you're just interested in trying Django, this is the easiest choice. SQLite is included in Python, so you won't need to install anything else to support your database.

What database does Django test use?

Writing tests Django's unit tests use a Python standard library module: unittest . This module defines tests using a class-based approach.


1 Answers

Append the following lines in your settings:

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' 

Make sure your actual database setting comes before them.

like image 60
shanyu Avatar answered Sep 30 '22 15:09

shanyu