The patchers
-============
+------------
The patch decorators are used for patching objects only within the scope of
the function they decorate. They automatically handle the unpatching for you,
patch
------
+~~~~~
.. note::
patch.object
-------------
+~~~~~~~~~~~~
.. function:: patch.object(target, attribute, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
patch.dict
-----------
+~~~~~~~~~~
.. function:: patch.dict(in_dict, values=(), clear=False, **kwargs)
patch.multiple
---------------
+~~~~~~~~~~~~~~
.. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
.. _start-and-stop:
patch methods: start and stop
------------------------------
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All the patchers have `start` and `stop` methods. These make it simpler to do
patching in `setUp` methods or where you want to do multiple patches without
TEST_PREFIX
------------
+~~~~~~~~~~~
All of the patchers can be used as class decorators. When used in this way
they wrap every test method on the class. The patchers recognise methods that
Nesting Patch Decorators
-------------------------
+~~~~~~~~~~~~~~~~~~~~~~~~
If you want to perform multiple patches then you can simply stack up the
decorators.
.. _where-to-patch:
Where to patch
---------------
+~~~~~~~~~~~~~~
`patch` works by (temporarily) changing the object that a *name* points to with
another one. There can be many names pointing to any individual object, so
Patching Descriptors and Proxy Objects
---------------------------------------
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Both patch_ and patch.object_ correctly patch and restore descriptors: class
methods, static methods and properties. You should patch these on the *class*
MagicMock and magic method support
-==================================
+----------------------------------
.. _magic-methods:
Mocking Magic Methods
----------------------
+~~~~~~~~~~~~~~~~~~~~~
:class:`Mock` supports mocking the Python protocol methods, also known as
"magic methods". This allows mock objects to replace containers or other
Magic Mock
-----------
+~~~~~~~~~~
There are two `MagicMock` variants: `MagicMock` and `NonCallableMagicMock`.
Helpers
-=======
+-------
sentinel
---------
+~~~~~~~~
.. data:: sentinel
DEFAULT
--------
+~~~~~~~
.. data:: DEFAULT
functions to indicate that the normal return value should be used.
-
call
-----
+~~~~
.. function:: call(*args, **kwargs)
create_autospec
----------------
+~~~~~~~~~~~~~~~
.. function:: create_autospec(spec, spec_set=False, instance=False, **kwargs)
ANY
----
+~~~
.. data:: ANY
FILTER_DIR
-----------
+~~~~~~~~~~
.. data:: FILTER_DIR
mock_open
----------
+~~~~~~~~~
.. function:: mock_open(mock=None, read_data=None)
.. _auto-speccing:
Autospeccing
-------------
+~~~~~~~~~~~~
Autospeccing is based on the existing `spec` feature of mock. It limits the
api of mocks to the api of an original object (the spec), but it is recursive