简体   繁体   中英

Error when trying to use `assert not mock.method.called`

I'm trying to assert that a method is not called using Python Mock. Unfortunately, I can't seem to get past this error:

AttributeError: MockCallable instance has no attribute 'called'

I'm running Python 2.7.1 and Python Mock 0.1.0 for my tests. Google says: No results found for "AttributeError: MockCallable instance has no attribute 'called'". How can I resolve this error?

Here's the test:

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'

You must update you mock library by pip . Attribute called was introduced in 0.4.0 as you can see in http://www.voidspace.org.uk/python/mock/changelog.html#version-0-4-0

Anyway by update it you will get a lot of more useful facilities and tools.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM