I'm pleased to announce a new release of the mock module, the first in a while. Konrad Delong has joined me as a maintainer of mock and has been a great help in getting this release out. As there are several major new features this is a beta release, with 0.7.0 final coming out in a few weeks assuming there are no major problems discovered. Please download it and try it out:
mock is a Python module that provides a core Mock class. It is intended to reduce the need for creating a host of trivial stubs throughout your test suite. After performing an action, you can make assertions about which methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way.
mock is tested on Python versions 2.4-2.7 and Python 3.
Full documentation is included in the distribution.
Changes in 0.7.0 (including the much awaited magic method support) are:
* Addition of ``mocksignature`` * Ability to mock magic methods * Ability to use patch and patch.object as class decorators * Renamed ``patch_object`` to ``patch.object`` (``patch_object`` is deprecated) * Addition of ``MagicMock`` class with all magic methods pre-created for you * Python 3 compatibility (tested with 3.2 but should work with 3.0 & 3.1 as well) * Addition of ``patch.dict(...)`` for changing dictionaries during a test * Addition of ``mocksignature`` argument to ``patch`` and ``patch_object`` * ``help(mock)`` works now (on the module). Can no longer use ``__bases__`` as a valid sentinel name (thanks to Stephen Emslie for reporting and diagnosing this) * Addition of soft comparisons: call_args, call_args_list and method_calls return now tuple-like objects which compare equal even when empty args or kwargs are skipped * Added some docstrings. * BUGFIX: ``side_effect`` now works with ``BaseException`` exceptions like ``KeyboardInterrupt`` * BUGFIX: patching the same object twice now restores the patches correctly * The tests now require `unittest2 http://pypi.python.org/pypi/unittest2`_ to run * `Konrad Delong http://konryd.blogspot.com/`_ added as co-maintainer
The main tasks before a 0.7.0 final release are finishing the documentation and docstrings, plus allowing `patch.dict(...)` to act as a context manager (currently decorator only).
All the best,