Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Mox to mock a module function and allow it to be called in almost any way

Tags:

python

mox

I have a function A that call another function B several times. I want to mock B in such a way that any number of calls that have the correct number of arguments, regardless of value, will return a fixed vale and be treated as correct.

If or how many times the the function is called is not a part of the spec.

like image 809
BCS Avatar asked Jan 21 '23 15:01

BCS


2 Answers

Stub out B normally....

Assuming B accepts 2 arguments and should return 'foo':

B(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn('foo')
like image 99
DonGar Avatar answered Jan 29 '23 07:01

DonGar


def B(*args, **kwds):
   return 'fixed value'
like image 23
nosklo Avatar answered Jan 29 '23 08:01

nosklo