Lines Matching refs:target

688                         f'Cannot autospec attr {name!r} from target '
690 f'[target={self!r}, attr={result.spec!r}]')
1299 f'target has already been mocked out. [spec_set={spec_set!r}]')
1399 target = self.getter()
1406 original = target.__dict__[name]
1408 original = getattr(target, name, DEFAULT)
1412 if name in _builtins and isinstance(target, ModuleType):
1417 "%s does not have the attribute %r" % (target, name)
1427 self.target = self.getter()
1527 if _is_instance_mock(self.target):
1530 f'target has already been mocked out. '
1531 f'[target={self.target!r}, attr={autospec!r}]')
1533 target_name = getattr(self.target, '__name__', self.target)
1535 f'Cannot autospec attr {self.attribute!r} from target '
1537 f'[target={self.target!r}, attr={autospec!r}]')
1552 setattr(self.target, self.attribute, new_attr)
1571 setattr(self.target, self.attribute, self.temp_original)
1573 delattr(self.target, self.attribute)
1574 if not self.create and (not hasattr(self.target, self.attribute) or
1579 setattr(self.target, self.attribute, self.temp_original)
1583 del self.target
1608 def _get_target(target):
1610 target, attribute = target.rsplit('.', 1)
1613 f"Need a valid target to patch. You supplied: {target!r}")
1614 return partial(pkgutil.resolve_name, target), attribute
1618 target, attribute, new=DEFAULT, spec=None,
1623 patch the named member (`attribute`) on an object (`target`) with a mock
1635 if type(target) is str:
1637 f"{target!r} must be the actual object to be patched, not a str"
1639 getter = lambda: target
1646 def _patch_multiple(target, spec=None, create=False, spec_set=None,
1668 if type(target) is str:
1669 getter = partial(pkgutil.resolve_name, target)
1671 getter = lambda: target
1696 target, new=DEFAULT, spec=None, create=False,
1701 manager. Inside the body of the function or with statement, the `target`
1705 If `new` is omitted, then the target is replaced with an
1712 `target` should be a string in the form `'package.module.ClassName'`. The
1713 `target` is imported and the specified object replaced with the `new`
1714 object, so the `target` must be importable from the environment you are
1715 calling `patch` from. The target is imported when the decorated function
1770 getter, attribute = _get_target(target)