【发布时间】:2015-08-29 00:04:52
【问题描述】:
我有一个函数,我已经用 @transaction.commit_on_success 进行了封装,并在其上运行 Django 单元测试。
函数太长,无法粘贴,但有一些伪代码是:
@transaction.commit_on_success
def func():
order = Order.create()
order.save()
OrderItem.create(order=order)
test = 10/0 # make sure we run into an error
然后在我的单元测试中我检查len(Order.objects.all()) == 0
我的函数正在返回一个有效的 Order 对象,因此事务正在提交。
我在这里做错了什么?
编辑:我在 Django 1.5
【问题讨论】:
标签: python django django-database django-unittest