Here is my class:
class GoogleCloudLayer:
def deleteMachine(self, machineName):
return machineName + ' is dead. (stubbed)'
It works:
>>> gc = GoogleCloudLayer()
>>> gc.deleteMachine('test')
test is dead (stubbed)
But I want to use in test and I want to have the assert_called_with
method defined on it:
from mock import MagicMock
#Stubbing with itself just so it will have the `assert_called_with` method defined on it
GoogleCloudLayer.deleteMachine = MagicMock(side_effect = GoogleCloudLayer.deleteMachine)
But then I get
>>> gc = GoogleCloudLayer()
>>> gc.deleteMachine('test')
unbound method deleteMachine() must be called with GoogleCloudLayer instance as first argument (got str instance instead)
If I change production code to gc.deleteMachine(gc, 'test')
it works.
But we don't want that , do we?