Django M2M现场单元测试没有失败

时间:2017-07-11 12:19:05

标签: django unit-testing

我有一个模型Notification

class Notification:
  reports = ManytoManyField()

在我的代码中,我有这一行:

Notification.objects.create(reports=reports_list)

上面在运行时抛出数据库约束违规(与报告fk有关),但是,当使用单元测试执行相同的代码时,没有错误。我甚至断言结果并通过,例如:

notification = Notification.objects.create(reports=reports_list)
...
notification.refresh_from_db()
self.assertEqual(notification.reports.count(), 10)

这是这种情况下的预期行为吗?

0 个答案:

没有答案