2009-10-01 21 views
4

單元測試就會失敗,我可以通過使用loaddata在我的Django應用程序加載夾具文件:夾具裝載工作與loaddata但在Django

manage.py loaddata palamut 

夾具palamut.yaml是目錄palamut/fixtures/

我在palamut/tests/中有一個單元測試模塊service_tests.py。其內容是在這裏:

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. 

我調試的腳本,發現該夾具沒有單元測試模塊加載。

對此行爲的原因有任何建議嗎?

順便說一句,測試日誌不包含夾具加載相關的任何東西。

回答

9

您的TestCase應該是django.test.TestCase的一個實例,而不是unittest.TestCase