There are many examples online and in the docs of patching static methods on classes, or mocking the entire class. What I want to do is create a new method on an existing class which is in a library that I do not own - requests.Response.
I tried the code below but it doesn't appear to work
import requests # has requests.Response class
from unittest.mock import patch
def foo(self):
print("foo called")
return self.text
patch.object(requests.Response, "foo", foo)
# many tests down here which get a response object and call response.foo()
Is what I am trying to do possible?