Skip to content

Instantly share code, notes, and snippets.

@beyoung
Forked from igniteflow/mock-object-property.py
Created September 16, 2020 01:31
Show Gist options
  • Save beyoung/31cea1b544c67b009a4b36dd8ad9c3be to your computer and use it in GitHub Desktop.
Save beyoung/31cea1b544c67b009a4b36dd8ad9c3be to your computer and use it in GitHub Desktop.
How to mock an object property in Python
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment