requests-mock
requests-mock copied to clipboard
Expand type of _RequestObjectProxy.text to be Optional
We can see in the following example that .text can be None:
import requests
import requests_mock
def text_callback(request, context):
return str(type(request.text))
session = requests.Session()
with requests_mock.Mocker() as adapter:
adapter.register_uri(
"GET",
"mock://test.com/3",
text=text_callback,
)
resp = session.get("mock://test.com/3")
assert resp.status_code == 200
print(
"Response text: ", resp.text
) # prints 'Response text: <class 'NoneType'>'