Commit 90155366 authored by Michael Foord's avatar Michael Foord

Adding an example to unittest.mock.patch documentation

parent 54b3db8c
...@@ -984,6 +984,15 @@ patch ...@@ -984,6 +984,15 @@ patch
`patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
available for alternate use-cases. 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 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 class is instantiated in the code under test then it will be the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment