Lines Matching defs:patch
10 'patch',
1261 # _check_spec_arg_typos takes kwargs from commands like patch and checks that
1337 if not attr.startswith(patch.TEST_PREFIX):
1423 """Perform the patch."""
1529 f'Cannot autospec attr {self.attribute!r} as the patch '
1569 """Undo the patch."""
1590 """Activate a patch, returning any created mock."""
1597 """Stop an active patch."""
1601 # If the patch hasn't been started this will fail
1613 f"Need a valid target to patch. You supplied: {target!r}")
1623 patch the named member (`attribute`) on an object (`target`) with a mock
1626 `patch.object` can be used as a decorator, class decorator or a context
1628 `autospec` and `new_callable` have the same meaning as for `patch`. Like
1629 `patch`, `patch.object` takes arbitrary keyword arguments for configuring
1632 When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
1652 with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
1655 Use `DEFAULT` as the value if you want `patch.multiple` to create
1657 function by keyword, and a dictionary is returned when `patch.multiple` is
1660 `patch.multiple` can be used as a decorator, class decorator or a context
1662 `autospec` and `new_callable` have the same meaning as for `patch`. These
1663 arguments will be applied to *all* patches done by `patch.multiple`.
1665 When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
1675 'Must supply at least one keyword argument with patch.multiple'
1695 def patch(
1700 `patch` acts as a function decorator, class decorator or a context
1703 the patch is undone.
1707 `MagicMock` otherwise. If `patch` is used as a decorator and `new` is
1709 decorated function. If `patch` is used as a context manager the created
1715 calling `patch` from. The target is imported when the decorated function
1719 if patch is creating one for you.
1722 patch to pass in the object being mocked as the spec/spec_set object.
1739 By default `patch` will fail to replace attributes that don't exist. If
1740 you pass in `create=True`, and the attribute doesn't exist, patch will
1749 code when your test methods share a common patchings set. `patch` finds
1750 tests by looking for method names that start with `patch.TEST_PREFIX`.
1752 You can specify an alternative prefix by setting `patch.TEST_PREFIX`.
1757 "as"; very useful if `patch` is creating a mock object for you.
1763 `patch` takes arbitrary keyword arguments. These will be passed to
1767 `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
1795 `patch.dict` can also be called with arbitrary keyword arguments to set
1798 with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
1801 `patch.dict` can be used as a context manager, decorator or class
1802 decorator. When used as a class decorator `patch.dict` honours
1803 `patch.TEST_PREFIX` for choosing which methods to wrap.
1850 if (attr.startswith(patch.TEST_PREFIX) and
1913 """Activate a patch, returning any created mock."""
1920 """Stop an active patch."""
1924 # If the patch hasn't been started this will fail
1941 for patch in reversed(_patch._active_patches):
1942 patch.stop()
1945 patch.object = _patch_object
1946 patch.dict = _patch_dict
1947 patch.multiple = _patch_multiple
1948 patch.stopall = _patch_stopall
1949 patch.TEST_PREFIX = 'test'