odoo:如何在 odoo 上创建失败或例外的单元测试场景?
odoo : How to create failed or exeption unit test scenario on odoo?
我为 odoo 模块创建了一些单元测试。现在我需要测试抛出错误消息 UserError 的异常情况。我在日志单元测试节目中看到:
运行 0.284 秒内进行 1 次测试
失败
我要登录:
运行 5.790 秒内进行 1 次测试
好的
是否可以在 odoo 单元测试中进行?以及如何创建它?
谢谢
你必须使用 assertRaises
def test_case1(self):
with self.assertRaises(SomeException):
do_something()
https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises
关于我的情况:
with self.assertRaises(Exception) as context:
my_object.button_confirm()
# context.exception[0] is your error message example 'Ups wrong choice'
self.assertTrue('Ups wrong choice' == context.exception[0])
我为 odoo 模块创建了一些单元测试。现在我需要测试抛出错误消息 UserError 的异常情况。我在日志单元测试节目中看到:
运行 0.284 秒内进行 1 次测试
失败
我要登录:
运行 5.790 秒内进行 1 次测试
好的
是否可以在 odoo 单元测试中进行?以及如何创建它? 谢谢
你必须使用 assertRaises
def test_case1(self):
with self.assertRaises(SomeException):
do_something()
https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises
关于我的情况:
with self.assertRaises(Exception) as context:
my_object.button_confirm()
# context.exception[0] is your error message example 'Ups wrong choice'
self.assertTrue('Ups wrong choice' == context.exception[0])