ANN: Mock 0.5.0 Release

F

Fuzzyman

Mock 0.5.0 has just been released.

* Mock Homepage http://www.voidspace.org.uk/python/mock/
* Download Mock 0.5.0 release (zip) http://www.voidspace.org.uk/downloads/mock-0.5.0.zip
* Mock Documentation as a PDF http://www.voidspace.org.uk/downloads/mock.pdf
* Mock entry on PyPI http://pypi.python.org/pypi/mock/
* Repository and Issue Tracker on Google Code http://code.google.com/p/mock/

This *isn't* backwards compatible as it cleans up the API in a few
ways, but they're all good changes I promise. {sm;:wink:}

One of the new features is that the Mock class now supports wrapping
objects; using the ``wraps`` keyword.

One of the other big changes is that the documentation is now built
with the ever-wonderful Sphinx, so the homepage is new and there also
a PDF of the documentation.

Mock is a library for the creation of simple mock objects that track
how they are used so that you can make assertions. It uses the action -
assertion pattern rather than the record -> replay pattern. Action -
assertion puts your tests after you have used the objects, which
seems more natural and means that you can make assertions about only
the behavior you are interested in. Mock also contains two decorators
(``patch`` and ``patch_object``) which make it easy to safely mock out
dependencies in the module under test purely within the scope of the
test itself (unpatching is done automatically on exit whether or not
the test passes). One of the changes in this release is that these
decorators also become context managers allowing them to be used with
the 'with statement'.

Mock can be installed with:

``easy_install mock``

The changelog for all changes in this release is:

* Made DEFAULT part of the public api.
* Documentation built with Sphinx.
* ``side_effect`` is now called with the same arguments as the mock is
called with and
if returns a non-DEFAULT value that is automatically set as the
``mock.return_value``.
* ``wraps`` keyword argument used for wrapping objects (and passing
calls through to the wrapped object).
* ``Mock.reset`` renamed to ``Mock.reset_mock``, as reset is a common
API name.
* ``patch`` / ``patch_object`` are now context managers and can be
used with ``with``.
* A new 'create' keyword argument to patch and patch_object that
allows them to patch
(and unpatch) attributes that don't exist. (Potentially unsafe to
use - it can allow
you to have tests that pass when they are testing an API that
doesn't exist - use at
your own risk!)
* The methods keyword argument to Mock has been removed and merged
with spec. The spec
argument can now be a list of methods or an object to take the spec
from.
* Nested patches may now be applied in a different order (created
mocks passed
in the opposite order). This is actually a bugfix.
* patch and patch_object now take a spec keyword argument. If spec is
passed in as 'True' then the Mock created will take the object it is
replacing
as its spec object. If the object being replaced is a class, then
the return
value for the mock will also use the class as a spec.
* A Mock created without a spec will not attempt to mock any magic
methods / attributes
(they will raise an ``AttributeError`` instead).

Many thanks to all those who gave feedback, feature requests and
patches!

What *isn't* in 0.5.0 is support for mocking magic methods. I do have
a technique in mind for this, which I implemented for the container
methods. It is very clean, but different from the pattern used to mock
out other methods. As I'm not currently using it I'm going to wait
until I need it and see if it works well in practise.

If you're interested in trying it, the code (with full documentation)
in a 'magics branch':

* http://code.google.com/p/mock/source/browse/#svn/branches/magics
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top