ANNOUNCE: Python Mock Objects

Dave dave at see.sig.for.address
Wed Mar 28 20:55:48 CEST 2001


[This is a repost, since the original seems to have got lost between
me and my ISP. My appologies if you receive it twice.]


I have released to the Python and XP communities a small Python module
for creating mock objects.  A mock object can be passed to a class or
method being tested to replace objects that are outside the scope of
the test. 

The file has been uploaded to the Extreme Programming mailing list on
yahoo groups, and may be downloaded from:
http://groups.yahoo.com/group/extremeprogramming/files/PythonMock.zip 

The idea is simple.  A mock object created with this class will allow
any method to be invoked on it, with any parameters (including keyword
arguments).  The method calls are stored and can be examined later to
see what parameters were passed.  By default all methods return None,
but the class constructor can take a dictionary of method names and
values to return for those methods.

The zip file contains documentation and a test suite using OmPyUnit,
which should easily be convertible to the other versions of PyUnit.
OmPyUnit can be downloaded from
http://www.xprogramming.com/software.htm or from
http://www.objectmentor.com/freeware/downloads.html.

If anyone finds this useful or converts it to other languages then
please let me know.  I believe Smalltalk or Ruby should be easy, but
if
anyone figures out how to do this in Java or C++ then please let
*everyone* know.  8^)


Share and Enjoy

        Dave Kirby

--------------------------------------------------
All great ideas start as heresy and end as dogma.

dkirby@   <-figure this out, spambots!
bigfoot.   My opinions are my own,
com        but I'm willing to share.



More information about the Python-list mailing list