[TIP] [python] Re: Mock Testing Patterns
Michael Foord
fuzzyman at voidspace.org.uk
Mon Nov 19 10:01:15 PST 2007
Gary Bernhardt wrote:
> On Nov 18, 2007 7:27 PM, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>
>> Do any of the mocking libraries support this pattern - asserting what
>> methods were called afterwards rather than setting expectations ahead of
>> the actions?
>>
>
> MiniMock does, if you use it with doctests. MiniMock is super simple
> - it just prints out every method call to the mock objects. You don't
> have to set up expectations ahead of time, although you do have to
> tell it what the mocked functions should return (otherwise the code
> under test wouldn't be fooled!) If you use it in a doctest, the
> printed method calls will have to match what appears in the doctest.
> So the "verification" step just falls out for free - it just becomes
> another part of the doctest's expected output.
>
>
Yes - I just looked at minimock. :-)
It is perilously close to what we what we need, but aimed mainly at doctest.
As is the way with Python, rolling your own is very easy. I've created a
mock class (< 50 LOC) that meets about 90% of our needs. I'll post it soon.
Michael
http://www.manning.com/foord
More information about the testing-in-python
mailing list