diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-03-28 14:32:08 (GMT) |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-03-28 14:32:08 (GMT) |
commit | 901553668a4505d9c101ad9fe7edd6bd15a252ba (patch) | |
tree | f36d8a0244e6805d17748c687f85c86e4f4c6421 /Doc/library/unittest.mock.rst | |
parent | 54b3db8c849e039c6d43141bd1351d6eb743679d (diff) | |
download | cpython-901553668a4505d9c101ad9fe7edd6bd15a252ba.zip cpython-901553668a4505d9c101ad9fe7edd6bd15a252ba.tar.gz cpython-901553668a4505d9c101ad9fe7edd6bd15a252ba.tar.bz2 |
Adding an example to unittest.mock.patch documentation
Diffstat (limited to 'Doc/library/unittest.mock.rst')
-rw-r--r-- | Doc/library/unittest.mock.rst | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 2fe5849..df6665b 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 |