|| ||Fuzzyman <fuzzyman-AT-gmail.com>|
|| ||ANN: Mock 0.4.0 released|
|| ||Mon, 13 Oct 2008 04:18:25 -0700 (PDT)|
Mock 0.4.0 has just been released, the first release in about ten
months (but worth the wait).
Mock is a simple library for testing: specifically for mocking,
stubbing and patching.
* Mock Homepage & Documentation http://www.voidspace.org.uk/python/mock.html
* mock.py (module only) <http://www.voidspace.org.uk/downloads/mock.py
* mock-0.4.0.zip (module, tests and documentation) <http://
* mock.txt (documentation) <http://www.voidspace.org.uk/python/docs/
* Google Code Home & Subversion Repository <http://code.google.com/p/
This new release brings in some cool new features, but some are
backwards incompatible so read the release notes if you are updating.
Thanks to all those who emailed me with
suggestions and feature requests - *most* of them got in one way or
What is Mock?
Mock makes simple mocking trivially easy. It also provides decorators
to help patch module and class level attributes within the scope of a
test. In this release the ``patch`` decorator got even easier to use.
You can now call it with one argument - a string which is the fully
qualified name of the object you wish to patch, in the form
'package_name.module_name.ClassName'. ``patch`` patches the class in
the specified module with a Mock object, which is passed in to the
decorated function. (As well as ``patch`` creating mocks for you, you
can also explicitly pass in an alternative object to patch with.)
The are now eggs (for Python 2.4-2.6) up on the `Mock Cheeseshop Page
<http://pypi.python.org/pypi/mock/>`_. This means that if you have
setuptools you should be able to install mock with:
The full changelog is:
* Default return value is now a new mock rather than None
* 'return_value' added as a keyword argument to the constructor
* New method 'assert_called_with'
* Added 'side_effect' attribute / keyword argument called when mock is
* patch decorator split into two decorators:
- ``patch_object`` which takes an object and an attribute name to
(plus optionally a value to patch with which defaults to a mock
- ``patch`` which takes a string specifying a target to patch; in
'package.module.Class.attribute'. (plus optionally a value to
patch with which defaults to a mock object)
* Can now patch objects with ``None``
* Change to patch for nose compatibility with error reporting in
* Reset no longer clears children / return value etc - it just resets
call count and call args. It also calls reset on all children (and
the return value if it is a mock).
Thanks to Konrad Delong, Kevin Dangoor and others for patches and
See the following for examples of using Mock and patch:
Support the Python Software Foundation:
to post comments)