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
|