[TIP] [Chicago] ANN: Fudge: python mock / stub framework

Kumar McMillan kumar.mcmillan at gmail.com
Tue Feb 3 11:56:08 PST 2009

On Tue, Feb 3, 2009 at 1:18 PM, Ian Bicking <ianb at colorstudy.com> wrote:
> In the latest release of minimock (1.1) instead of simply logging everything
> to stdout, it can write to a MockTracker, and you can use it from unittest.

ah, I don't think that was there when I last peeked at minimock

> It doesn't deal with expectations directly, but I'm not sure what that would
> add over checking that expectations after the run?  I guess that's the same
> criticism as for mock?

I have a lot of non-framework mock code that checks expectations after
the run (post mortem approach).  I don't like this as much, just seems
like too much work.  You don't really gain any benefits that I can
think of.

With the declarative approach (jMock, fudge) you have to be careful to
always call fudge.stop() and possibly fudge.clear_expectations() since
there is a global registry.  I think that's what most people are
annoyed with who prefer the post mortem approach.  So far, I am not
annoyed by this but there's still time :)

> Looking at pyMock, I wonder if the clever use of sys.settrace could be used
> for some not-quite-mocking tests, especially applying tests to code that
> wasn't written to be testable.

yeah, possibly.  Scotch does something similar to produce twill tests
from a real user browsing a website
(http://darcs.idyll.org/~t/projects/scotch/doc/).  The catch with the
record / playback is you need to actually run the code (which may not
always be feasible, say, if you are trying to produce an obscure SOAP
fault in a web service or something).  Also, what you get out of it is
typically a regression test.  I have a love / hate relationship with
regression tests.  They seem to pile up and can slow down a test suite
over time.  I much prefer to fix a bug by adding failing unit tests
for those units at fault as opposed to making some sort of black box
functional test that reproduces the bug.  Sometimes you need that
black box test though to help locate the culprit.


> --
> Ian Bicking  |  http://blog.ianbicking.org
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago

More information about the testing-in-python mailing list