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

有没有办法加载不驻留在appname / fixtures中的灯具? 根据django文档,灯具必须位于INSTALLED_APPS目录中


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


只需使用call_command以编程方式调用“loaddata”。 你可以在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/52303.html

上一篇: Django loading fixtures (not from installed apps) in tests

下一篇: No fixtures found when testing an app on Django