summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-03-28 15:10:06 +0100
committerMichael Foord <michael@voidspace.org.uk>2012-03-28 15:10:06 +0100
commit2a2b0dd94deec0c508b88aa42ca7de8ceeaa47d2 (patch)
tree74edf3b7e5397937930dd5d6e03c77a126bfe467
parentddb89d4bb08f6ecce38ef9b15bab670331c43256 (diff)
downloadmock-2a2b0dd94deec0c508b88aa42ca7de8ceeaa47d2.tar.gz
Doc / docstring improvement for patch
-rw-r--r--docs/patch.txt25
-rw-r--r--mock.py25
2 files changed, 28 insertions, 22 deletions
diff --git a/docs/patch.txt b/docs/patch.txt
index d27dbc5..e166459 100644
--- a/docs/patch.txt
+++ b/docs/patch.txt
@@ -44,17 +44,20 @@ patch
`patch` acts as a function decorator, class decorator or a context
manager. Inside the body of the function or with statement, the `target`
- (specified in the form `'package.module.ClassName'`) is patched
- with a `new` object. When the function/with statement exits the patch is
- undone.
-
- The `target` is imported and the specified attribute patched with the new
- object, so it must be importable from the environment you are calling the
- decorator from. The target is imported when the decorated function is
- executed, not at decoration time.
-
- If `new` is omitted, then a new `MagicMock` is created and passed in as an
- extra argument to the decorated function.
+ is patched with a `new` object. When the function/with statement exits
+ the patch is undone.
+
+ If `new` is omitted, then the target is replaced with a
+ :class:`MagicMock`. If `patch` is used as a decorator and `new` is
+ omitted, the created mock is passed in as an extra argument to the
+ decorated function. If `patch` is used as a context manager the created
+ mock is returned by the context manager.
+
+ `target` should be a string in the form `'package.module.ClassName'`. The
+ `target` is imported and the specified object replaced with the `new`
+ object, so the `target` must be importable from the environment you are
+ calling `patch` from. The target is imported when the decorated function
+ is executed, not at decoration time.
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
if patch is creating one for you.
diff --git a/mock.py b/mock.py
index efb55df..6ae565b 100644
--- a/mock.py
+++ b/mock.py
@@ -1456,17 +1456,20 @@ def patch(
"""
`patch` acts as a function decorator, class decorator or a context
manager. Inside the body of the function or with statement, the `target`
- (specified in the form `'package.module.ClassName'`) is patched
- with a `new` object. When the function/with statement exits the patch is
- undone.
-
- The `target` is imported and the specified attribute patched with the new
- object, so it must be importable from the environment you are calling the
- decorator from. The target is imported when the decorated function is
- executed, not at decoration time.
-
- If `new` is omitted, then a new `MagicMock` is created and passed in as an
- extra argument to the decorated function.
+ is patched with a `new` object. When the function/with statement exits
+ the patch is undone.
+
+ If `new` is omitted, then the target is replaced with a
+ `MagicMock`. If `patch` is used as a decorator and `new` is
+ omitted, the created mock is passed in as an extra argument to the
+ decorated function. If `patch` is used as a context manager the created
+ mock is returned by the context manager.
+
+ `target` should be a string in the form `'package.module.ClassName'`. The
+ `target` is imported and the specified object replaced with the `new`
+ object, so the `target` must be importable from the environment you are
+ calling `patch` from. The target is imported when the decorated function
+ is executed, not at decoration time.
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
if patch is creating one for you.