0

我试图断言没有使用 Python Mock 调用方法。不幸的是,我似乎无法克服这个错误:

AttributeError: MockCallable instance has no attribute 'called'

我正在为我的测试运行 Python 2.7.1 和 Python Mock 0.1.0。谷歌说:No results found for "AttributeError: MockCallable instance has no attribute 'called'".我该如何解决这个错误?

这是测试:

import unittest2
import main
from mock import Mock

class TestCli(unittest2.TestCase):
    def setUp(self):
        self.mockView = Mock()
        self.mockFriendManager = Mock()
        self.mockedCli = main.CLI(self.mockView, self.mockFriendManager)

[...]

    def testCliDoesntGetFriendPropertiesWhenNotSelected(self):
        view = Mock( { "requestResponse":2 } )
        friendManager = Mock()
        cli = main.CLI(view, friendManager)
        cli.outputMenu()
        assert not friendManager.getFriendProperties.called, 'hello'
4

1 回答 1

1

您必须mock通过 更新您的库pip。属性called是在 0.4.0 中引入的,您可以在http://www.voidspace.org.uk/python/mock/changelog.html#version-0-4-0中看到

无论如何,通过更新它,您将获得更多有用的设施和工具。

于 2014-11-20T07:45:28.510 回答