Django loading fixtures (not from installed apps) in tests

Is there a way to load fixtures that do NOT reside in appname/fixtures? According to django docs, fixtures have to be in directory of INSTALLED_APPS


您可以使用FIXTURE_DIRS设置来定义其他位置以搜索灯具:https: FIXTURE_DIRS : FIXTURE_DIRS


Just had to programmatically call 'loaddata' using call_command. You can do it in setUp.

from django.test import TestCase
from django.core.management import call_command

class GlobalSetup(TestCase):
    def setUp(self):
        # Manually calling loaddata to import fixures 
        # that are not in INSTALLED_APPS
        call_command('loaddata', 'cur_dir/fixtures_name', verbosity=0)
链接地址: http://www.djcxy.com/p/52304.html

上一篇: 我可以测试一个Django应用程序,而无需初始化

下一篇: Django在测试中加载装置(不是来自已安装的应用程序)