I am trying to mock an instance method in Python with a side_effect. I want/expect my side effect to be called with an initial 'self' argument that I can use to determine the return value.
So I have something like this:
import mock
class TestCases(unittest.TestCase):
@mock.patch('Item.exists')
def test_foo(self, mock_item_exists):
def item_exists_side_effect(*args, **kwargs):
# I expect args[0] here to be supplied and to refer to the item
_self = args[0]
return _self.name == 'bar'
mock_item_exists.side_effect = item_exists_side_effect
...
However, when Item.exists() gets called I end up in my side-effect function but with an empty args list.
Is this expected? Am I doing something wrong?