unit testing - Get parameters of a mocked method in python -
i using python's unittest.mock framework.
i want achieve following goal mock:
the original method like:
def mymethod(para1, para2, para3): return para1 + para2 + para3
i want mock return first para1 - discard rest:
def mymethod(para1, para2, para3): return para1
i saw can set return_value of mocked object, seems hardcoded one. saw can parameters of mocked call, after called. - there way parameter , return dynamically?
using side_effect
of mock class:
import mock def mymethod(para1, para2, para3): return para1 + para2 + para3 m = mock.mock(side_effect=lambda *args: args[0]) mock.patch('__main__.mymethod', m): assert mymethod(1, 2, 3) == 1
Comments
Post a Comment