Skip to content

Commit 274efdf

Browse files
committed
Add a documentation example on read only database tests. Refs #418.
1 parent 59feb76 commit 274efdf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/database.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,28 @@ Put this in ``conftest.py``::
426426
INSERT INTO theapp_item (name) VALUES ('created from a sql script');
427427
''')
428428

429+
430+
Use a read only database
431+
""""""""""""""""""""""""
432+
433+
You can replace the ordinary `django_db_setup` to completely avoid database
434+
creation/migrations. If you have no need for rollbacks or truncating tables,
435+
you can simply avoid blocking the database and use it directly. When using this
436+
method you must ensure that your tests do not change the database state.
437+
438+
439+
Put this in ``conftest.py``::
440+
441+
import pytest
442+
443+
444+
@pytest.fixture(scope='session')
445+
def django_db_setup():
446+
"""Avoid creating/setting up the test database"""
447+
pass
448+
449+
450+
@pytest.fixture
451+
def db_access_without_rollback_and_truncate(request, django_db_setup, django_db_blocker):
452+
django_db_blocker.unblock()
453+
request.addfinalizer(django_db_blocker.restore)

0 commit comments

Comments
 (0)