通常,您希望从django的unittest类TestCase继承,可以从django.测试. 也就是说,您可以将msg参数传递给您要评估的任何内容,其中包含失败消息。在
以下是“人性化”的一个例子:class HumanizeTests(TestCase):
def humanize_tester(self, test_list, result_list, method):
# Using max below ensures we go through both lists
# However, if the lists are not equal length, this raises an exception
for test_content, result in zip(test_list, result_list):
t = Template('{%% load humanize %%}{{ test_content|%s }}' % method)
rendered = t.render(Context(locals())).strip()
self.assertEqual(rendered, escape(result),
msg="%s test failed, produced '%s', should've produced '%s'" % (method, rendered, result))
显然,你的不需要看起来像上面这样,但是你可以看到msg参数的作用。在