MCPcopy Index your code
hub / github.com/python/cpython / _patch_object

Function _patch_object

Lib/unittest/mock.py:1693–1719  ·  view source on GitHub ↗

patch the named member (`attribute`) on an object (`target`) with a mock object. `patch.object` can be used as a decorator, class decorator or a context manager. Arguments `new`, `spec`, `create`, `spec_set`, `autospec` and `new_callable` have the same meaning as for `patch`. L

(
        target, attribute, new=DEFAULT, spec=None,
        create=False, spec_set=None, autospec=None,
        new_callable=None, *, unsafe=False, **kwargs
    )

Source from the content-addressed store, hash-verified

1691
1692
1693def _patch_object(
1694 target, attribute, new=DEFAULT, spec=None,
1695 create=False, spec_set=None, autospec=None,
1696 new_callable=None, *, unsafe=False, **kwargs
1697 ):
1698 """
1699 patch the named member (`attribute`) on an object (`target`) with a mock
1700 object.
1701
1702 `patch.object` can be used as a decorator, class decorator or a context
1703 manager. Arguments `new`, `spec`, `create`, `spec_set`,
1704 `autospec` and `new_callable` have the same meaning as for `patch`. Like
1705 `patch`, `patch.object` takes arbitrary keyword arguments for configuring
1706 the mock object it creates.
1707
1708 When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
1709 for choosing which methods to wrap.
1710 """
1711 if type(target) is str:
1712 raise TypeError(
1713 f"{target!r} must be the actual object to be patched, not a str"
1714 )
1715 getter = lambda: target
1716 return _patch(
1717 getter, attribute, new, spec, create,
1718 spec_set, autospec, new_callable, kwargs, unsafe=unsafe
1719 )
1720
1721
1722def _patch_multiple(target, spec=None, create=False, spec_set=None,

Callers

nothing calls this directly

Calls 1

_patchClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…