91
votes

What is your single favorite mocking library for Python?

7
minimock which uses doctest - Prof. Falken
"Mockito is a mocking framework that tastes really good. It lets you write beautiful tests with clean & simple API. Mockito doesn't give you hangover because the tests are very readable and they produce clean verification errors." code.google.com/p/mockito - mit

7 Answers

43
votes

I've only used one, but I've had good results with Michael Foord's Mock: http://www.voidspace.org.uk/python/mock/.

Michael's introduction says it better than I could:

There are already several Python mocking libraries available, so why another one?

Most mocking libraries follow the 'record -> replay' pattern of mocking. I prefer the 'action -> assertion' pattern, which is more readable and intuitive particularly when working with the Python unittest module.

...

It also provides utility functions / objects to assist with testing, particularly monkey patching.

5
votes

Mocker from Gustavo Niemeyer.

It's not perfect, but it is very powerful and flexible.

4
votes
4
votes

I'm the author for mocktest. I think it's pretty fully featured and easy to use, but I might be biased:

http://gfxmonk.net/dist/doc/mocktest/doc/

3
votes

pyDoubles the test doubles framework for Python, by iExpertos.com. It supports mocks, stubs, spies and matchers, including Hamcrest matchers

0
votes

I've used pMock in the past, and didn't mind it, it had pretty decent docs too. However, Foord's Mock as mentioned above is also nice.