third_party/py/mock/html/changelog.html
Note that due to changes in tox, mock is no longer tested with Python 2.4. The compatibility code has not been removed so it probably still works, but tests are no longer run.
No changes since 1.0.0 beta 1. This version has feature parity with unittest.mock in Python 3.3.
Full list of changes since 0.8:
The standard library version!
The only changes since 0.8rc2 are:
Full List of changes since 0.7:
mock 0.8.0 is the last version that will support Python 2.4.
Special thanks to Julian Berman for his help with diagnosing and improving performance in this release.
mock 0.8.0 is the last version that will support Python 2.4.
The patchers (patch, patch.object and patch.dict), plus Mock and MagicMock, take arbitrary keyword arguments for configuration
New mock method configure_mock for setting attributes and return values / side effects on the mock and its attributes
In Python 2.6 or more recent, dir on a mock will report all the dynamically created attributes (or the full list of attributes if there is a spec) as well as all the mock methods and attributes.
Module level FILTER_DIR added to control whether dir(mock) filters private attributes. True by default. Note that vars(Mock()) can still be used to get all instance attributes and dir(type(Mock()) will still return all the other attributes (irrespective of FILTER_DIR)
patch and patch.object now create a MagicMock instead of a Mock by default
Added ANY for ignoring arguments in assert_called_with calls
Addition of call helper object
Protocol methods on MagicMock are magic mocks, and are created lazily on first lookup. This means the result of calling a protocol method is a MagicMock instead of a Mock as it was previously
Added the Mock API (assert_called_with etc) to functions created by mocksignature
Private attributes _name, _methods, ‘_children’, _wraps and _parent (etc) renamed to reduce likelihood of clash with user attributes.
Implemented auto-speccing (recursive, lazy speccing of mocks with mocked signatures for functions/methods)
Added the create_autospec function for manually creating ‘auto-specced’ mocks
Removal of deprecated patch_object
Package fixes contributed by Michael Fladischer. No code changes.
No API changes since 0.7.0 rc1. Many documentation changes including a stylish new Sphinx theme.
The full set of changes since 0.6.0 are:
Changes since beta 4:
Using spec with MagicMock only pre-creates magic methods in the spec
Setting a magic method on a mock with a spec can only be done if the spec has that method
Mocks can now be named (name argument to constructor) and the name is used in the repr
mocksignature can now be used with classes (signature based on __init__) and callable objects (signature based on __call__)
Mocks created with a spec can now pass isinstance tests (__class__ returns the type of the spec)
Default numeric value for MagicMock is 1 rather than zero (because the MagicMock bool defaults to True and 0 is False)
Improved failure message for assert_called_with() when the mock has not been called at all
Adding the following to the set of supported magic methods:
Added ‘build_sphinx’ command to setup.py (requires setuptools or distribute) Thanks to Florian Bauer
with statement tests now skipped on Python 2.4
Tests require unittest2 to run on Python 2.7
Improved several docstrings and documentation
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:
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.
patch maintains the name of decorated functions for compatibility with nose test autodiscovery.
Tests decorated with patch that use the two argument form (implicit mock creation) will receive the mock(s) passed in as extra arguments.
Thanks to Kevin Dangoor for these changes.
Removed patch_module. patch can now take a string as the first argument for patching modules.
The third argument to patch is optional - a mock will be created by default if it is not passed in.
Bug fix, allows reuse of functions decorated with patch and patch_module.
Added spec keyword argument for creating Mock objects from a specification object.
Added patch and patch_module monkey patching decorators.
Added sentinel for convenient access to unique objects.
Distribution includes unit tests.
Initial release.
Contributions, bug reports and comments welcomed!
Feature requests and bug reports are handled on the issue tracker:
wraps is not integrated with magic methods.
patch could auto-do the patching in the constructor and unpatch in the destructor. This would be useful in itself, but violates TOOWTDI and would be unsafe for IronPython & PyPy (non-deterministic calling of destructors). Destructors aren’t called in CPython where there are cycles, but a weak reference with a callback can be used to get round this.
Mock has several attributes. This makes it unsuitable for mocking objects that use these attribute names. A way round this would be to provide methods that hide these attributes when needed. In 0.8 many, but not all, of these attributes are renamed to gain a _mock prefix, making it less likely that they will clash. Any outstanding attributes that haven’t been modified with the prefix should be changed.
If a patch is started using patch.start and then not stopped correctly then the unpatching is not done. Using weak references it would be possible to detect and fix this when the patch object itself is garbage collected. This would be tricky to get right though.
When a Mock is created by patch, arbitrary keywords can be used to set attributes. If patch is created with a spec, and is replacing a class, then a return_value mock is created. The keyword arguments are not applied to the child mock, but could be.
When mocking a class with patch, passing in spec=True or autospec=True, the mock class has an instance created from the same spec. Should this be the default behaviour for mocks anyway (mock return values inheriting the spec from their parent), or should it be controlled by an additional keyword argument (inherit) to the Mock constructor? create_autospec does this, so an additional keyword argument to Mock is probably unnecessary.
The mocksignature argument to patch with a non Mock passed into new_callable will probably cause an error. Should it just be invalid?
Note that NonCallableMock and NonCallableMagicMock still have the unused (and unusable) attributes: return_value, side_effect, call_count, call_args and call_args_list. These could be removed or raise errors on getting / setting. They also have the assert_called_with and assert_called_once_with methods. Removing these would be pointless as fetching them would create a mock (attribute) that could be called without error.
Some outstanding technical debt. The way autospeccing mocks function signatures was copied and modified from mocksignature. This could all be refactored into one set of functions instead of two. The way we tell if patchers are started and if a patcher is being used for a patch.multiple call are both horrible. There are now a host of helper functions that should be rationalised. (Probably time to split mock into a package instead of a module.)
Passing arbitrary keyword arguments to create_autospec, or patch with autospec, when mocking a function works fine. However, the arbitrary attributes are set on the created mock - but create_autospec returns a real function (which doesn’t have those attributes). However, what is the use case for using autospec to create functions with attributes that don’t exist on the original?
mocksignature, plus the call_args_list and method_calls attributes of Mock could all be deprecated.
Enter search terms or a module, class or function name.
© Copyright 2007-2012, Michael Foord & the mock team. Last updated on Nov 05, 2012. Created using Sphinx 1.1.3.