如何在Python Mockito中模拟类属性

加内什·萨特普特

我正在使用Mockito编写测试用例。我的代码看起来像这样

def function_to_test():
    dog = lib1.get_dog()
    return dog.weight

我的测试代码如下所示

def test_method1():
    dog_mock = mock()
    when(lib1).get_dog().thenReturn(dog_mock)
    when(dog).weight.thenReturn(10)  # <-- I'm not sure how do I write this?

由于dog.weight不是一种方法。我该如何嘲笑它?

马龙

我不熟悉用于Python的Mockito框架,但我认为您应该只在模拟对象上设置属性。像这样:

dog_mock = mock()
dog_mock.weight = 100
when(lib1).get_dog().thenReturn(dog_mock)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章