summaryrefslogtreecommitdiff
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-01-23 18:42:41 +0000
committerIrit Katriel <iritkatriel@yahoo.com>2022-01-23 18:50:44 +0000
commit4f13987fe8d9de2297deaf048f47a35d6908e84f (patch)
tree5501f2a732144881fdc3f517a439ecb8c978131e /Lib/unittest/mock.py
parent94d6434ba7ec3e4b154e515c5583b0b665ab0b09 (diff)
downloadcpython-git-backport-f7955a8-3.9.tar.gz
bpo-41403: Improve error message for invalid mock target (GH-30833)backport-f7955a8-3.9
(cherry picked from commit f7955a82e36d4c32ebdd7b7707cdf0e6ffa7a418)
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 5c78274d09..3f5442ed80 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1557,9 +1557,9 @@ class _patch(object):
def _get_target(target):
try:
target, attribute = target.rsplit('.', 1)
- except (TypeError, ValueError):
- raise TypeError("Need a valid target to patch. You supplied: %r" %
- (target,))
+ except (TypeError, ValueError, AttributeError):
+ raise TypeError(
+ f"Need a valid target to patch. You supplied: {target!r}")
getter = lambda: _importer(target)
return getter, attribute