summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-04-13 16:39:16 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2012-04-13 16:39:16 (GMT)
commit656319e58d80478c7aa2a783606f0b50053529ae (patch)
tree80e54a5ab0f5bac83555ca929453bb5292ce18ec /Lib/unittest/mock.py
parent899ee613f7b4a4f5967943095d5fbc9522356ad3 (diff)
downloadcpython-656319e58d80478c7aa2a783606f0b50053529ae.zip
cpython-656319e58d80478c7aa2a783606f0b50053529ae.tar.gz
cpython-656319e58d80478c7aa2a783606f0b50053529ae.tar.bz2
Make unittest.mock.create_autospec resilient against AttributeError on original object
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index ec17542..04eba91 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2044,10 +2044,14 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None,
# object to mock it so we would rather trigger a property than mock
# the property descriptor. Likewise we want to mock out dynamically
# provided attributes.
- # XXXX what about attributes that raise exceptions on being fetched
+ # XXXX what about attributes that raise exceptions other than
+ # AttributeError on being fetched?
# we could be resilient against it, or catch and propagate the
# exception when the attribute is fetched from the mock
- original = getattr(spec, entry)
+ try:
+ original = getattr(spec, entry)
+ except AttributeError:
+ continue
kwargs = {'spec': original}
if spec_set: