4

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.

BCS
  • 75,627
  • 68
  • 187
  • 294

2 Answers2

8

Stub out B normally....

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

B(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn('foo')
BCS
  • 75,627
  • 68
  • 187
  • 294
DonGar
  • 7,344
  • 8
  • 29
  • 32
  • doesn't seem to handle the zero call case: `ExpectedMethodCallsError: Verify: Expected methods never called` – BCS Dec 06 '13 at 19:15
  • That's true, and I'm not sure how to fix it... except this is a much easier problem with 'mock' which I now use most of the time. – DonGar May 24 '15 at 18:20
1
def B(*args, **kwds):
   return 'fixed value'
nosklo
  • 217,122
  • 57
  • 293
  • 297