Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand type of _RequestObjectProxy.text to be Optional #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamtheturtle
Copy link

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

We can see in the following example that `.text` can be `None`:

```python
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'>'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant