![](https://secure.gravatar.com/avatar/133b712423066c858d82f5d285a6867a.jpg?s=120&d=mm&r=g)
Yay for conference driven development, I got the final release of mock 0.7.0 done in time for PyCon. No api changes since the release candidate. The only changes are documentation improvements (double yay!) * http://pypi.python.org/pypi/mock/ (download) * http://www.voidspace.org.uk/python/mock/ (documentation) * https://code.google.com/p/mock/ (repo and issue tracker) At PyCon I gave a talk on mock. It was an intro talk on how to use mock and why you should use it, but also covered some of the shiny new features in 0.7.0. The video of the talk is up (thanks to the PyCon video team): * PyCon Video: Testing with mock https://blip.tv/file/4881513 Here's the release announcement for mock 0.7.0 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 big change since 0.7.0 rc 1 is documentation changes including a stylish new Sphinx theme. https://github.com/coordt/ADCtheme/ Three new pages particularly worth looking at are: * Mocking Magic Methods http://www.voidspace.org.uk/python/mock/magicmock.html * Further examples of mock http://www.voidspace.org.uk/python/mock/examples.html * Comparison with other mock frameworks http://www.voidspace.org.uk/python/mock/compare.html The full set of changes since 0.6.0 are: http://www.voidspace.org.uk/python/mock/changelog.html#version-0-7-0 * Python 3 compatibility * Ability to mock magic methods with `Mock` and addition of `MagicMock` with pre-created magic methods * Addition of `mocksignature` and `mocksignature` argument to `patch` and `patch.object` * Addition of `patch.dict` for changing dictionaries during a test * Ability to use `patch`, `patch.object` and `patch.dict` as class decorators * Renamed ``patch_object`` to `patch.object` (``patch_object`` is deprecated) * Addition of soft comparisons: `call_args`, `call_args_list` and `method_calls` now return tuple-like objects which compare equal even when empty args or kwargs are skipped * patchers (`patch`, `patch.object` and `patch.dict`) have start and stop methods * Addition of `assert_called_once_with` method * Mocks can now be named (`name` argument to constructor) and the name is used in the repr * 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 used, attempting to *set* an attribute on a mock not on the spec will raise an `AttributeError` * Mocks created with a spec can now pass `isinstance` tests (`__class__` returns the type of the spec) * Added docstrings to all objects * Improved failure message for `Mock.assert_called_with` when the mock has not been called at all * Decorated functions / methods have their docstring and `__module__` preserved on Python 2.4. * BUGFIX: `mock.patch` now works correctly with certain types of objects that proxy attribute access, like the django settings object * BUGFIX: mocks are now copyable (thanks to Ned Batchelder for reporting and diagnosing this) * BUGFIX: `spec=True` works with old style classes * BUGFIX: ``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) * BUGFIX: ``side_effect`` now works with ``BaseException`` exceptions like ``KeyboardInterrupt`` * BUGFIX: `reset_mock` caused infinite recursion when a mock is set as its own return value * BUGFIX: patching the same object twice now restores the patches correctly * with statement tests now skipped on Python 2.4 * Tests require unittest2 (or unittest2-py3k) to run * Tested with `tox <http://pypi.python.org/pypi/tox>`_ on Python 2.4 - 3.2, jython and pypy (excluding 3.0) * Added 'build_sphinx' command to setup.py (requires setuptools or distribute) Thanks to Florian Bauer * Switched from subversion to mercurial for source code control * `Konrad Delong <http://konryd.blogspot.com/>`_ added as co-maintainer
participants (1)
-
Fuzzyman