[Python-checkins] cpython: Adding an example to unittest.mock.patch documentation
michael.foord
python-checkins at python.org
Wed Mar 28 16:31:58 CEST 2012
http://hg.python.org/cpython/rev/635fe162934e
changeset: 75973:635fe162934e
user: Michael Foord <michael at voidspace.org.uk>
date: Wed Mar 28 15:32:08 2012 +0100
summary:
Adding an example to unittest.mock.patch documentation
files:
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
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -984,6 +984,15 @@
`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
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list