I\'m having a fairly difficult time using mock in Python:
def method_under_test():
r = requests.post(\"http://localhost/post\")
print r
A compact and simple way to do it is to use new_callable patch's attribute to force patch to use PropertyMock instead of MagicMock to create the mock object. The other arguments passed to patch will be used to create PropertyMock object.
with patch('requests.post.ok', new_callable=PropertyMock, return_value=True) as mock_post:
"""Your test"""