[TIP] [python] Re: Mock Testing Patterns

Gustavo Niemeyer gustavo at niemeyer.net
Mon Nov 19 03:55:25 PST 2007


Hello Michael,

> 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.

Another detail I find important in that regard is that I want the mocking
library to, as much as possible, explode right at the spot where the
expectation was broken.  This usually makes fixing the situation much more
straightforward.

-- 
Gustavo Niemeyer
http://niemeyer.net



More information about the testing-in-python mailing list