How to run Django s test database only in memory

0 votes
Since I know the test database will always be quite small, why can't I just configure the system to always keep the entire test database in RAM? Never touch the disk at all. How do I configure this in Django? I'd prefer to keep using MySQL since that's what I use in production, but if SQLite 3 or something else makes this easy.
Jun 24, 2020 in Python by kartik
• 37,520 points
4,342 views

1 answer to this question.

0 votes

Hello @kartik,

If you set your database engine to sqlite3 when you run your tests, Django will use a in-memory database.

I'm using code like this in my settings.py to set the engine to sqlite when running my tests:

if 'test' in sys.argv:
    DATABASE_ENGINE = 'sqlite3'

Or in Django 1.2:

if 'test' in sys.argv:
    DATABASES['default'] = {'ENGINE': 'sqlite3'}

And finally in Django 1.3 and 1.4:

if 'test' in sys.argv:
    DATABASES['default'] = {'ENGINE': 'django.db.backends.sqlite3'}

Hope this is helpfull!

Thank You!!

answered Jun 24, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
1 answer

How to run django unit-tests on production database in Python?

In case someone googles here searching for ...READ MORE

answered Nov 28, 2018 in Python by Nymeria
• 3,560 points
1,572 views
0 votes
2 answers

How do I connect to a MySQL Database in Python?

connect mysql database with python import MySQLdb db = ...READ MORE

answered Mar 28, 2019 in Python by rajesh
• 1,270 points
1,911 views
0 votes
1 answer

In python how to test a string for a substring

if "ABCD" in "xxxxABCDyyyy": This can be used ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 58,020 points
831 views
0 votes
1 answer

How to use Pandas HDF5 as a Database in Python?

HDF5 works fine for concurrent read only ...READ MORE

answered Nov 30, 2018 in Python by Nymeria
• 3,560 points

edited Dec 10, 2018 by Nymeria 1,343 views
0 votes
1 answer

How to Specify a mySQL ENUM in a Django model?

Hello @kartik, You can follow this snippet below: MAYBECHOICE ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,840 points
1,489 views
0 votes
1 answer
0 votes
1 answer

ERROR: mysql 1018 (HY000): Can't read dir of '.' (errno: 13)

Hello @kartik, You need to set ownership and ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,840 points
2,584 views
0 votes
1 answer

Error:No module named MySQLdb

Hii @kartik, Try this code: pip install PyMySQL and then ...READ MORE

answered Jun 26, 2020 in Python by Niroj
• 82,840 points
15,356 views
0 votes
1 answer

How to output text from database with line breaks in a django template?

Hello @kartik, Use linebreaks or linebreaksbr filter: {{ text|linebreaks }} Or surround the text ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,840 points
13,551 views
0 votes
1 answer

How to set up a PostgreSQL database in Django?

Hello @kartik, Steps that I use: - sudo apt-get ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,840 points
898 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP