Author: | Michael Foord |
---|---|
Co-maintainer: | Konrad Delong |
Version: | Mock 0.7.0 beta 1 |
Date: | 2010/06/XX |
Homepage: | Mock Homepage |
Download: | Mock on PyPI |
Documentation: | PDF Documentation |
License: | BSD License |
Support: | Testing in Python Email List |
Issue tracker: | Google code project |
mock provides a core mock.Mock class that is intended to reduce the need to create 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 specific attributes in the normal way.
The mock module also provides a mock.patch() decorator that handles patching module and class level attributes within the scope of a test, along with mock.sentinel for creating unique objects.
Mock is very easy to use and is designed for use with unittest. Mock is based on the ‘action -> assertion’ pattern instead of ‘record -> replay’ used by many mocking frameworks.
mock is tested on Python versions 2.4-2.7 and Python 3.
The current version is 0.7.0 beta 1, dated XXXX. Mock is still experimental; the API may change. If you find bugs or have suggestions for improvements / extensions then please email me.
You can checkout the latest development version from the Google Code Subversion repository with the following command:
svn checkout http://mock.googlecode.com/svn/trunk/ mock-read-only
If you have pip, setuptools or distribute you can install mock with:
easy_install mockpip install mock
Alternatively you can download the mock distribution from PyPI and after unpacking run:
python setup.py install
Articles and blog entries on testing with Mock:
Mock uses unittest2 for its own test suite. In order to run it, use the unit2 script that comes with unittest2 module on a checkout of the source repository:
unit2 discover
On Python 2.7 and 3.2 you can use unittest module from the standard library.
python3.2 -m unittest discover
On Python 2.4 you will see one failure - testwith.py will fail to import as it uses the with statement which is invalid syntax under Python 2.4.
All Python versions except 2.6 & 2.7 will have at least one skip due to tests using unsupported functionality, or on Python 3 the tests for unicode not being relevant.