mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Adding an example to unittest.mock.patch documentation
This commit is contained in:
parent
54b3db8c84
commit
901553668a
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue