[TIP] ANN: mock 0.7.0 beta 4 released

Michael Foord michael at voidspace.org.uk
Tue Nov 16 04:50:25 PST 2010

Hello tip,

I've released mock 0.7.0 beta 4. This is intended to be the last release 
of 0.7.0 before the final.

mock is a Python library for simple mocking and patching (replacing 
objects with mocks during test runs). The "headline features" in 0.7.0 
are Python 3 support and the ability to mock magic methods. You can now 
mock objects that behave like containers or are used as context 
managers. mock is designed for use with unittest, based on the action -> 
assertion pattern rather than record -> replay. People are happily using 
mock with Python test frameworks like nose and py.test.

0.7.0 is a major new release with a bunch of other new features and 
bugfixes as well.

The latest beta is now up on PyPI. 0.7.0 beta 4 is intended to be the 
last release before 0.7.0 final (read my lips - no new features), so 
please try it out and report any issues.


The work remaining before the final release is updating the 
documentation, especially the examples, to include the new features.

Changes since beta 3 are:

* patchers (patch, patch.object and patch.dict) have start and stop methods
* Addition of assert_called_once_with method
* repr of a mock with a spec includes the class name of the spec
* assert_called_with works with python -OO
* New spec_set keyword argument to Mock and patch. If this is set, 
attempting to set an attribute on a mock not on the spec will raise an 
* Attributes and return value of a MagicMock are MagicMock objects
* Attempting to set an unsupported magic method now raises an AttributeError
* patch.dict works as a class decorator
* Switched from subversion to mercurial for source code control
* BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting 
and diagnosing this)
* BUGFIX: spec=True works with old style classes
* BUGFIX: mocksignature=True can now patch instance methods via patch.object

For more details, including full changelog since 0.6.0 and examples of 
using the new start / stop methods on patchers, see the announcement on 
my blog:


All the best,

Michael Foord



READ CAREFULLY. By accepting and reading this email you agree,
on behalf of your employer, to release me from all obligations
and waivers arising from any and all NON-NEGOTIATED agreements,
licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap,
confidentiality, non-disclosure, non-compete and acceptable use
policies (”BOGUS AGREEMENTS”) that I have entered into with your
employer, its partners, licensors, agents and assigns, in
perpetuity, without prejudice to my ongoing rights and privileges.
You further represent that you have the authority to release me
from any BOGUS AGREEMENTS on behalf of your employer.

More information about the testing-in-python mailing list