让我们考虑这个例子:
class First:
def register(self, handler):
pass
class Second:
def __init__(self, first):
assert first
self.__first = first
测试注入模拟:
class TestSecond(PyMockTestCase):
def test_construction(self):
first = self.mock()
sut = Second(first)
此测试失败,因为first
未通过断言。如果我修改我的Second
课程以测试None
,则测试将通过:
class Second:
def __init__(self, first):
assert first is not None
self.__first = first
是什么原因导致模拟被识别为False
?