我正在用json制作一组数据来运行单一测试,但是我遇到了一个问题,如果有人可以帮助我,我会很感激。
json文件是:
[
{"pk":1,
"model":"key_process_indicator_bsc.StrategicType",
"fields":{
"name":"UEN",
"created_at": "2015-11-11",
"modified_at": "2015-11-11",
"deleted": 0
}
}
]
并且单一测试是:
from django.test import TestCase
from key_process_indicator_bsc.models import *
class ModelsTestCase(TestCase):
fixtures = ['test_data_key_process_indicator_bsc.json']
def test_levels(self):
StrategicType = StrategicType.objects.get(name = "UEN")
self.assertTrue(isinstance(StrategicType, StrategicType))
self.assertEqual(StrategicType.__str__(), StrategicType.name)
问题是:
ERROR: test_levels (key_process_indicator_bsc.unitary_test.test_models.ModelsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/leidyj/key_process_indicator_bsc_repository/key_process_indicator_bsc/key_process_indicator_bsc/unitary_test/test_models.py",
line 8, in test_levels
StrategicType = StrategicType.objects.get(name = "UEN")
UnboundLocalError: local variable 'StrategicType' referenced before assignment
----------------------------------------------------------------------
感谢;