requests-mock icon indicating copy to clipboard operation
requests-mock copied to clipboard

Expand type of _RequestObjectProxy.text to be Optional

Open adamtheturtle opened this issue 1 year ago • 0 comments

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'>'

adamtheturtle avatar Jul 15 '24 17:07 adamtheturtle