[Django]-Pytest django load database data from yaml file

4👍

If you are using the pytest-django package then you can load Django data fixtures for your tests by providing a django_db_setup fixture pytest fixture in conftest.py

import pytest

from django.core.management import call_command

@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
    with django_db_blocker.unblock():
        call_command('loaddata', 'my_fixture.yaml')

Leave a comment