Programmatically replacing an API for another module

Tom Plunket tomas at fancy.org
Tue Nov 21 20:00:32 EST 2006


Bruno Desthuilliers wrote:

> > I've got a bunch of code that runs under a bunch of unit tests.  It'd
> > be really handy if when testing I could supply replacement
> > functionality to verify that the right things get called without those
> > things actually getting called, since frequently those calls take a
> > long time to execute and do things that, well, I don't really want to
> > do.
> 
> Congratulation, you just rediscovered the MockObject.

How do I rediscover something that I'm explicitly implementing?  I had
set out specifically to mock an API, there was no rediscovery going
on.

That does allow me to discover via Google the Python Mock Module,
though, which may well do what I want:

from TestedModule import *

my_win32file = Mock({
   'CopyFile': 'CopyFile called'
   }

win32file = my_win32file

...perhaps.

I'm just a bit loathe to download and install more stuff when
something simpler appears to be near-at-hand.  ...especially
considering the page describing this module doesn't offer any download
links!  http://python-mock.sourceforge.net/


-tom!



More information about the Python-list mailing list