我可以使用 loaddata 在我的 django 应用程序中加载夹具文件:
manage.py loaddata palamut
夹具palamut.yaml
在目录中palamut/fixtures/
我有一个单元测试模块service_tests.py
。palamut/tests/
它的内容在这里:
import unittest
from palamut.models import *
from palamut.service import *
from palamut.pforms import *
class ServiceTest(unittest.TestCase):
fixtures = ['palamut.yaml']
def test_convert_vensim(self):
game_definition = GameDefinition.objects.get(pk=1)
此单元测试给出以下错误:
DoesNotExist: GameDefinition matching query does not exist.
我调试了脚本,发现在单元测试模块中没有加载夹具。
您对这种行为的原因有什么建议吗?
顺便说一句,测试日志不包含任何与夹具加载相关的内容。