【发布时间】:2011-08-31 12:31:55
【问题描述】:
我做了一个简单的测试用例:
def setUp(self):
self.testListNone = None
def testListSlicing(self):
self.assertRaises(TypeError, self.testListNone[:1])
我期待测试通过,但我遇到了异常:
Traceback (most recent call last):
self.assertRaises(TypeError, self.testListNone[:1])
TypeError: 'NoneType' object is unsubscriptable
我认为 assertRaises 会通过,因为 TypeError 异常会 被抚养?
【问题讨论】:
-
ongspxm.github.io/blog/2016/11/… 你可以参考这个文档,因为他/她已经解释了为什么使用 lambda/context manager 来包装代码
标签: python unit-testing