You need to use return_value
and PropertyMock
:
with patch('requests.post') as patched_post:
type(patched_post.return_value).ok = PropertyMock(return_value=True)
This means: when calling requests.post
, on the return value of that call, set a PropertyMock
for the property ok
to return the value True
.