Fixture加载与loaddata一起使用,但在Django的单元测试中无声地失败

Mer*_*glu 4 python django unit-testing fixtures

我可以使用loaddata在我的django应用程序中加载fixture文件:

manage.py loaddata palamut
Run Code Online (Sandbox Code Playgroud)

夹具palamut.yaml位于目录中palamut/fixtures/

我有一个单元测试模块service_tests.pypalamut/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)
Run Code Online (Sandbox Code Playgroud)

此单元测试给出以下错误:

DoesNotExist: GameDefinition matching query does not exist.
Run Code Online (Sandbox Code Playgroud)

我调试了脚本,发现夹具没有加载到单元测试模块中.

你对这种行为的原因有什么建议吗?

顺便说一下,测试日志不包含任何与夹具加载相关的内容.

ogg*_*ggy 9

您的TestCase应该是django.test.TestCase的实例,而不是unittest.TestCase