File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -333,3 +333,29 @@ Put this into ``conftest.py``::
333
333
'HOST': 'db.example.com',
334
334
'NAME': 'external_db',
335
335
}
336
+
337
+
338
+ Populate the database with initial test data
339
+ """"""""""""""""""""""""""""""""""""""""""""
340
+
341
+ This example shows how you can populate the test database with test data. The
342
+ test data will be saved in the database, i.e. it will not just be part of a
343
+ transactions. This example uses Django's fixture loading mechanism, but it can
344
+ be replaced with any way of loading data into the database.
345
+
346
+ Notice that :fixture: `django_db_setup ` is in the argument list. This may look
347
+ odd at first, but it will make sure that the sure that the original
348
+ pytest-django fixture is used to create the test database. When
349
+ ``call_command `` is invoked, the test database is already prepared and
350
+ configured.
351
+
352
+ Put this in conftest.py::
353
+
354
+ import pytest
355
+
356
+ from django.core.management import call_command
357
+
358
+ @pytest.fixture(scope='session')
359
+ def django_db_setup(django_db_setup, django_db_blocker):
360
+ with django_db_blocker:
361
+ call_command('loaddata', 'your_data_fixture.json')
You can’t perform that action at this time.
0 commit comments