[BangPypers] What is the best Python Mock library

Siddharta siddharta.lists at gmail.com
Thu Jan 28 05:16:06 CET 2010


Couple of years ago I wrote silvermock - 
http://github.com/silverstripe/silvermock

It uses an expectation style like so:

mock = MockObject("mock class", [
ShouldBeCalled("__init__"),
ShouldBeCalled("function").with_args((1,2))
])
obj = mock()
obj.function(1,2)
mock._instance.verify()

You can see more usage examples in the MockObjectTest suite.

There is also

minimock - http://pypi.python.org/pypi/MiniMock
Python Mocker - http://labix.org/mocker

--
Siddharta Govindaraj

On 27-Jan-10 6:37 PM, Diptanu Choudhury wrote:
> Yes, and also the unit tests tend to become more verbose with Mox.
>
> On Wed, Jan 27, 2010 at 2:42 PM, Noufal Ibrahim<noufal at gmail.com>  wrote:
>
>    
>> On Wed, Jan 27, 2010 at 6:05 PM, Diptanu Choudhury
>> <admin.nitjece at gmail.com>  wrote:
>>      
>>> Hi,
>>>
>>> We ran into a discussion this afternoon about the various Python Mocking
>>> Libraries. The popular one out there seems to be Mox(according to
>>> my colleagues), though I like Mock(python-mock).
>>>
>>> I would like to hear the views of the python veterans of this list about
>>>        
>> the
>>      
>>> popular mocking libraries! :-)
>>>        
>> I recently needed one and looked through a few. I found the whole
>> record/replay style a little weird and preferred a post mortem
>> approach. With that in mind, I found
>> http://www.voidspace.org.uk/python/mock/ quite nice and it's what I
>> use.
>>
>>
>>
>>
>> --
>> ~noufal
>> http://nibrahim.net.in
>> _______________________________________________
>> BangPypers mailing list
>> BangPypers at python.org
>> http://mail.python.org/mailman/listinfo/bangpypers
>>
>>      
>
>
>    



More information about the BangPypers mailing list