File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -426,3 +426,28 @@ Put this in ``conftest.py``::
426
426
INSERT INTO theapp_item (name) VALUES ('created from a sql script');
427
427
''')
428
428
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)
You can’t perform that action at this time.
0 commit comments