From: Michael Foord Date: Wed, 28 Mar 2012 14:32:08 +0000 (+0100) Subject: Adding an example to unittest.mock.patch documentation X-Git-Tag: v3.3.0a2~30^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=901553668a4505d9c101ad9fe7edd6bd15a252ba;p=python Adding an example to unittest.mock.patch documentation --- diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 2fe5849b45..df6665be1d 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -984,6 +984,15 @@ patch `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. +`patch` as function decorator, creating the mock for you and passing it into +the decorated function: + + >>> @patch('__main__.SomeClass') + ... def function(mock_class): + ... print(mock_class is SomeClass) + ... + >>> function() + True Patching a class replaces the class with a `MagicMock` *instance*. If the class is instantiated in the code under test then it will be the