==================================== Mock - Mocking and Testing Library ==================================== :Author: `Michael Foord `_ :Version: Mock 0.6.0 :Date: 2009/08/22 :Homepage: `Mock Homepage`_ :Documentation: `PDF Documentation `_ :License: `BSD License`_ :Support: `Testing in Python Email List `_ :Contact: fuzzyman@voidspace.org.uk .. _Mock Homepage: http://www.voidspace.org.uk/python/mock/ .. _BSD License: http://www.voidspace.org.uk/python/license.shtml .. module:: mock :synopsis: Mock object and testing tool library. Introduction ============ ``mock`` provides a core :class:`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. It also provides a :func:`mock.patch` decorator that handles patching module and class level attributes within the scope of a test, along with :const:`mock.sentinel` for creating unique objects. Most mocking libraries follow the 'record -> replay' pattern of mocking. I prefer the 'action -> assertion' pattern, which is more readable and intuitive; particularly when working with the Python `unittest module `_. For a discussion of the merits of the two approaches, see `Mocking, Patching, Stubbing: all that Stuff `_. Downloading =========== The current version is **0.6.0**, dated 23rd August 2009. Mock is still experimental; the API may change. If you find bugs or have suggestions for improvements / extensions then please email me. * `mock.py (module only) `_ * `mock-0.6.0.zip (module, tests and documentation) `_ * `mock documentation as PDF `_ * `Google Code Home & Subversion Repository `_ 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`` Mock is registered with PyPi (`Mock on PyPi `_). If you have pip or Distribute you can install mock with: | ``easy_install mock`` | ``pip mock`` API Documentation ================= .. toctree:: :maxdepth: 2 mock patch sentinel User Guide ========== .. toctree:: :maxdepth: 2 getting-started examples todo changelog References ========== Articles and blog entries on testing with Mock: * `Python mock testing techniques and tools `_ * `How To Test Django Template Tags `_ * `A presentation on Unit Testing with Mock `_ * `Mocking with Django and Google AppEngine `_