MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _patch_object

Function _patch_object

tools/python-3.11.9-amd64/Lib/unittest/mock.py:1620–1646  ·  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 `pat

(
        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

1618
1619
1620def _patch_object(
1621 target, attribute, new=DEFAULT, spec=None,
1622 create=False, spec_set=None, autospec=None,
1623 new_callable=None, *, unsafe=False, **kwargs
1624 ):
1625 """
1626 patch the named member (`attribute`) on an object (`target`) with a mock
1627 object.
1628
1629 `patch.object` can be used as a decorator, class decorator or a context
1630 manager. Arguments `new`, `spec`, `create`, `spec_set`,
1631 `autospec` and `new_callable` have the same meaning as for `patch`. Like
1632 `patch`, `patch.object` takes arbitrary keyword arguments for configuring
1633 the mock object it creates.
1634
1635 When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
1636 for choosing which methods to wrap.
1637 """
1638 if type(target) is str:
1639 raise TypeError(
1640 f"{target!r} must be the actual object to be patched, not a str"
1641 )
1642 getter = lambda: target
1643 return _patch(
1644 getter, attribute, new, spec, create,
1645 spec_set, autospec, new_callable, kwargs, unsafe=unsafe
1646 )
1647
1648
1649def _patch_multiple(target, spec=None, create=False, spec_set=None,

Callers

nothing calls this directly

Calls 2

_patchClass · 0.70
typeClass · 0.50

Tested by

no test coverage detected