Use SQLite file database for tests (and not in-memory)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Use SQLite file database for tests (and not in-memory)

Daniel Gilge
Hi,

Introduction:

Django uses an in-memory database for testing when it finds a SQLite database in the settings. However, the ChannelsLiveServerTestcase (of Channels 2.0) cannot be used with an in-memory database.

It was nice to still be able to use SQLite, because it doesn't have any dependencies and therefore it is the best database to be used for tests which have to work on all kind of systems (as far as I can see). I looked through the Django code to find the part where it is determined whether to use an in-memory database or not but I couldn't find it.

Question:

Could somebody give me a hint how to tell Django to use a SQLite database on filesystem for tests, please?

Regards,

Daniel

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1c36103e-17d3-41e3-81e2-aa8cc6213a3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Use SQLite file database for tests (and not in-memory)

Daniel Gilge
Ok, I found it. You just have to define a name for your test database in your settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase',
        'TEST': {
            'NAME': 'test_database',
        },
    },
}

Thanks!

Am Samstag, 10. März 2018 22:05:27 UTC+1 schrieb Daniel Gilge:
Hi,

Introduction:

Django uses an <a href="https://docs.djangoproject.com/en/2.0/topics/testing/overview/#the-test-database" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Ftopics%2Ftesting%2Foverview%2F%23the-test-database\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbvKxaKw_A0Rrbk_6ovG8vBbqBkg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.0%2Ftopics%2Ftesting%2Foverview%2F%23the-test-database\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbvKxaKw_A0Rrbk_6ovG8vBbqBkg&#39;;return true;">in-memory database for testing when it finds a SQLite database in the settings. However, the ChannelsLiveServerTestcase (of Channels 2.0) <a href="https://github.com/django/channels/issues/961" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fchannels%2Fissues%2F961\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-jXBQnx4BBnGbo9dvURCKM1zV1Q&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fchannels%2Fissues%2F961\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-jXBQnx4BBnGbo9dvURCKM1zV1Q&#39;;return true;">cannot be used with an in-memory database.

It was nice to still be able to use SQLite, because it doesn't have any dependencies and therefore it is the best database to be used for tests which have to work on all kind of systems (as far as I can see). I looked through the Django code to find the part where it is determined whether to use an in-memory database or not but I couldn't find it.

Question:

Could somebody give me a hint how to tell Django to use a SQLite database on filesystem for tests, please?

Regards,

Daniel

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87503033-1912-4fea-9639-5b9165b1c358%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.