What is your favorite Python mocking library? [closed]
Asked Answered
G

7

95

What is your single favorite mocking library for Python?

Gneiss answered 18/9, 2008 at 23:37 Comment(2)
minimock which uses doctestConductivity
"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/mockitoKing
G
43

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.

Gneiss answered 18/9, 2008 at 23:41 Comment(2)
mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards.Overcoat
Do NOT use backported mock with Python 2.x! It is last updated in 2012, riddled with bugs (see the issues on google code!). Stay away.Passer
C
8

Mox, from Google

Coldhearted answered 18/9, 2008 at 23:45 Comment(1)
I find it poorly documented, in a very non-intuitive way.Tower
A
5

Mocker from Gustavo Niemeyer.

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

Alow answered 19/9, 2008 at 11:36 Comment(1)
Mocker is extensively covered in Daniel Arbuckle's "Python Testing: Beginner's Guide" (Packt).Byword
C
5

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/

Cabbala answered 20/2, 2012 at 10:5 Comment(0)
J
4

Dingus, by Gary Bernhardt.

Jhvh answered 23/6, 2009 at 21:22 Comment(0)
R
3

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

Ruvalcaba answered 5/7, 2011 at 21:25 Comment(1)
The url redirect to a Chinesse site. bitbucket.org/DavidVilla/python-doublexCantabrigian
N
0

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.

Nagle answered 18/9, 2008 at 23:44 Comment(1)
That's what the pMock's author says about pMokc: "Just to note that pMock is no longer in development (really must update the web page), actually it was more an experiment I finished playing with about four years ago and assumed the "alpha" designation would scare people away." [brunningonline.net/simon/blog/archives/002262.html]Peking

© 2022 - 2024 — McMap. All rights reserved.