[TIP] [python] Re: Mock Testing Patterns

Blake Winton bwinton+python at latte.ca
Mon Nov 19 08:24:17 PST 2007


Gustavo Niemeyer wrote:
>> Well, the pattern is usually more like:
>> setup mocks
>> action
>> assertions
>> So yes, there is some setup to put the mocks in place.
>>
>> This pattern works *fine*, but we aren't yet using a mocking library. I 
>> wonder if there are any that will support us in this pattern rather than 
>> switching to recording expectations.
> 
> I find it unlikely.  As Martin explained, the setup work is needed in any
> case, as you have to specify return values, ordering between expressions,
> actions executed, and so on.  If you're going to setup these things ahead
> of time, you're actually already defining expectations.

I use the same pattern as Michael, and find it works just fine with Dave Kirby's
python-mock (located at http://python-mock.sourceforge.net/).  (Okay, I've
modified it a little to also take a dictionary of param->return value mappings,
but it's a trivial modification.)

Later,
Blake.





More information about the testing-in-python mailing list