Created
October 3, 2016 11:03
How to mock an object property in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
with mock.patch('path.to.ObjectClass.my_property', new_callable=mock.PropertyMock) as mock_my_property: | |
mock_my_property.return_value = 'my value' |
Assigning directly to a MagicMock
. From here:
mock_reader = mock.MagicMock()
type(mock_reader).content = mock.PropertyMock(return_value='whatever')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks