assertRaises in python unit-test not catching the exception [duplicate]

一世执手 提交于 2019-11-28 10:47:10

Unittest's assertRaises takes a callable and arguments, so in your case, you'd call it like:

self.assertRaises(ValueError, self.isone.is_one, 2)

If you prefer, as of Python2.7, you could also use it as a context manager like:

with self.assertRaises(ValueError):
    self.isone.is_one(2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!