【发布时间】:2015-06-02 05:49:53
【问题描述】:
我正在为 Django 中的自定义管理器编写测试套件,并且想要测试大量项目。
基本上,由于组合爆炸,它需要创建数千个项目。
我需要的是一种在数据库中创建 很多 django 对象的方法,并在整个测试类中保留它们,而不是重新创建它们。
我有以下代码:
class CustomConceptQuerySetTest(TestCase):
def setUp(self):
pass #make lots and lots of items.
def test_is_public(self):
pass # check if returned items in the object.public() queryset are actually "public"
def test_is_editable(self):
pass # check if returned items in the object.viewable() queryset are actually "viewable" only to certain users.
很遗憾,每次测试前都会调用setUp,但测试中内容并没有改变,只是读取,而且每次都是一样的。
在 Django 中有没有办法保留数据库,或者防止测试类中的回滚或破坏?
【问题讨论】:
标签: python django testing django-testing django-tests