Author michael.foord
Recipients kushal.das, michael.foord
Date 2014-04-16.16:15:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397664917.5.0.84660783066.issue21254@psf.upfronthosting.co.za>
In-reply-to
Content
What steps will reproduce the problem?

>>> import mock
>>> a_mock = mock.MagicMock()
>>> no_attribute = mock.PropertyMock(side_effect=AttributeError)
>>> type(a_mock).property = no_attribute



What is the expected output? What do you see instead?

I would expect the above to raise an AttributeError. Instead it returns a MagicMock instance.

>>> a_mock.property
<MagicMock name='mock.property' id='140165240345424'>

I would expect it to have the same effect as calling a PropertyMock with any other exception as a side effect:

>>> mock_value_error = mock.PropertyMock(side_effect=ValueError)
>>> type(a_mock).other_property = mock_value_error
>>> a_mock.other_property
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ahammel/bin/python/mock-1.0.1-py2.6.egg/mock.py", line 2365, in __get__
    return self()
  File "/home/ahammel/bin/python/mock-1.0.1-py2.6.egg/mock.py", line 955, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/home/ahammel/bin/python/mock-1.0.1-py2.6.egg/mock.py", line 1010, in _mock_call
    raise effect
ValueError



What version of the product are you using? On what operating system?

Using version mock-1.0.1-py2.6 on CentOS 6.4



Please provide any additional information below.

PropertyMock objects apparently won't raise sublcasses of AttributeError either:

>>> class MockAttributeError(AttributeError): pass
... 
>>> no_attr = mock.PropertyMock(side_effect=MockAttributeError)
>>> type(a_mock).property = no_attr
>>> a_mock.property
<MagicMock name='mock.property' id='140165240345424'>

Works fine for subclasses of other Exceptions:

>>> class MockKeyError(KeyError): pass
... 
>>> no_key = mock.PropertyMock(side_effect=MockKeyError)
>>> type(a_mock).property = no_key
>>> a_mock.property
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ahammel/bin/python/mock-1.0.1-py2.6.egg/mock.py", line 2365, in __get__
    return self()
  File "/home/ahammel/bin/python/mock-1.0.1-py2.6.egg/mock.py", line 955, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/home/ahammel/bin/python/mock-1.0.1-py2.6.egg/mock.py", line 1010, in _mock_call
    raise effect
__main__.MockKeyError
History
Date User Action Args
2014-04-16 16:15:17michael.foordsetrecipients: + michael.foord, kushal.das
2014-04-16 16:15:17michael.foordsetmessageid: <1397664917.5.0.84660783066.issue21254@psf.upfronthosting.co.za>
2014-04-16 16:15:17michael.foordlinkissue21254 messages
2014-04-16 16:15:16michael.foordcreate