projects
/
python
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
54b3db8
)
Adding an example to unittest.mock.patch documentation
author
Michael Foord
<michael@voidspace.org.uk>
Wed, 28 Mar 2012 14:32:08 +0000
(15:32 +0100)
committer
Michael Foord
<michael@voidspace.org.uk>
Wed, 28 Mar 2012 14:32:08 +0000
(15:32 +0100)
Doc/library/unittest.mock.rst
patch
|
blob
|
history
diff --git
a/Doc/library/unittest.mock.rst
b/Doc/library/unittest.mock.rst
index 2fe5849b45ef490bfba0f374c476de51506c0f4e..df6665be1dc365ec63bd00ac1d3834d5e2da828f 100644
(file)
--- 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