为什么PyMock创建的mock被认为是假的?

时间:2014-02-14 12:11:26

标签: python unit-testing python-2.7 assert pymock

让我们考虑这个例子:

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

0 个答案:

没有答案