ANN: Mock 0.4.0 released

F

Fuzzyman

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://
www.voidspace.org.uk/downloads/mock-0.4.0.zip
* mock.txt (documentation) <http://www.voidspace.org.uk/python/docs/
mock.txt
* Google Code Home & Subversion Repository <http://code.google.com/p/
mock/

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
another...

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.)


What's New?
==========

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:

``easy_install mock``

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
called
* patch decorator split into two decorators:

- ``patch_object`` which takes an object and an attribute name to
patch
(plus optionally a value to patch with which defaults to a mock
object)
- ``patch`` which takes a string specifying a target to patch; in
the form
'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
wrapped functions
* 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
suggestions.

See the following for examples of using Mock and patch:

* http://www.voidspace.org.uk/python/weblog/arch_d7_2008_10_11.shtml#e1019
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top