Mocking python function based on input arguments

后端 未结 8 529
无人及你
无人及你 2020-12-22 21:15

We have been using Mock for python for a while.

Now, we have a situation in which we want to mock a function

def foo(self, my_param):
    #do someth         


        
8条回答
  •  庸人自扰
    2020-12-22 22:15

    Side effect takes a function (which can also be a lambda function), so for simple cases you may use:

    m = MagicMock(side_effect=(lambda x: x+1))
    

提交回复
热议问题