mamba的Django测试运行程序(Python的最终测试运行程序)。
mamba-django的Python项目详细描述
曼巴江戈
mamba的Django测试运行程序。在
如何安装
pip install mamba-django
如何使用
转到您的Django测试设置并添加以下行
^{pr2}$然后执行Django测试
./manage.py test --settings=project.settings.test --keepdb
或者您可以执行将其作为参数传递的测试
./manage.py test --testrunner mamba_django.MambaRunner --settings=project.settings.test --keepdb
此外,还可以将所有mamba参数传递给Django test命令。在
例如:
./manage.py test --settings=project.settings.test --keepdb -f documentation -s 1
如何使用Django数据库事务执行mamba测试
fromexpectsimport(equal,expect)frommamba_djangoimport(start_django_transactions,rollback_django_transactions)frommyapp.modelsimportAnimalwithdescription("Mamba with Django")asself:withbefore.each:self.transactions=start_django_transactions()withcontext("Running atomic tests"):withit("creates an animal"):Animal.objects.create(name="lion",sound="roar")expect(Animal.objects.all().count()).to(equal(1))withit("creates another animal"):Animal.objects.create(name="lion",sound="roar")expect(Animal.objects.all().count()).to(equal(1))withafter.each:rollback_django_transactions(self.transactions)
如何加载Django设备
您可以使用方法load_fixtures
来加载Django fixtures。在
fromexpectsimport(equal,expect)frommamba_djangoimport(load_fixtures,start_django_transactions,rollback_django_transactions)fromdjango.contrib.auth.modelsimportGroupwithdescription("Mamba with Django")asself:withbefore.each:self.transactions=start_django_transactions()load_fixtures(['group.json'])withcontext("Fixtures"):withit("can retrieve loaded fixtures"):expect(Group.objects.all().count()).to(equal(1))withafter.each:rollback_django_transactions(self.transactions)
- 项目
标签: