mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Minor unittest.mock.patch doc / docstring improvement
This commit is contained in:
parent
a9e6fb201d
commit
54b3db8c84
2 changed files with 26 additions and 18 deletions
|
@ -920,17 +920,20 @@ patch
|
||||||
|
|
||||||
`patch` acts as a function decorator, class decorator or a context
|
`patch` acts as a function decorator, class decorator or a context
|
||||||
manager. Inside the body of the function or with statement, the `target`
|
manager. Inside the body of the function or with statement, the `target`
|
||||||
(specified in the form `'package.module.ClassName'`) is patched
|
is patched with a `new` object. When the function/with statement exits
|
||||||
with a `new` object. When the function/with statement exits the patch is
|
the patch is undone.
|
||||||
undone.
|
|
||||||
|
|
||||||
The `target` is imported and the specified attribute patched with the new
|
If `new` is omitted, then the target is replaced with a
|
||||||
object, so it must be importable from the environment you are calling the
|
:class:`MagicMock`. If `patch` is used as a decorator and `new` is
|
||||||
decorator from. The target is imported when the decorated function is
|
omitted, the created mock is passed in as an extra argument to the
|
||||||
executed, not at decoration time.
|
decorated function. If `patch` is used as a context manager the created
|
||||||
|
mock is returned by the context manager.
|
||||||
|
|
||||||
If `new` is omitted, then a new `MagicMock` is created and passed in as an
|
`target` should be a string in the form `'package.module.ClassName'`. The
|
||||||
extra argument to the decorated function.
|
`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`
|
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
|
||||||
if patch is creating one for you.
|
if patch is creating one for you.
|
||||||
|
|
|
@ -1350,19 +1350,24 @@ def patch(
|
||||||
spec_set=None, autospec=None, new_callable=None, **kwargs
|
spec_set=None, autospec=None, new_callable=None, **kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
`patch` acts as a function decorator, class decorator or a context
|
||||||
|
|
||||||
`patch` acts as a function decorator, class decorator or a context
|
`patch` acts as a function decorator, class decorator or a context
|
||||||
manager. Inside the body of the function or with statement, the `target`
|
manager. Inside the body of the function or with statement, the `target`
|
||||||
(specified in the form `'package.module.ClassName'`) is patched
|
is patched with a `new` object. When the function/with statement exits
|
||||||
with a `new` object. When the function/with statement exits the patch is
|
the patch is undone.
|
||||||
undone.
|
|
||||||
|
|
||||||
The `target` is imported and the specified attribute patched with the new
|
If `new` is omitted, then the target is replaced with a
|
||||||
object, so it must be importable from the environment you are calling the
|
`MagicMock`. If `patch` is used as a decorator and `new` is
|
||||||
decorator from. The target is imported when the decorated function is
|
omitted, the created mock is passed in as an extra argument to the
|
||||||
executed, not at decoration time.
|
decorated function. If `patch` is used as a context manager the created
|
||||||
|
mock is returned by the context manager.
|
||||||
|
|
||||||
If `new` is omitted, then a new `MagicMock` is created and passed in as an
|
`target` should be a string in the form `'package.module.ClassName'`. The
|
||||||
extra argument to the decorated function.
|
`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`
|
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
|
||||||
if patch is creating one for you.
|
if patch is creating one for you.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue