Make unittest.mock.create_autospec resilient against AttributeError on original object

This commit is contained in:
Michael Foord 2012-04-13 17:39:16 +01:00
parent 899ee613f7
commit 656319e58d
2 changed files with 29 additions and 2 deletions

View file

@ -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: