getsentry / getsentry/responses

How to use responses with cachecontrol?

Open
#780 1 comment 0 reactions 0 assignees View on GitHub
bug Waiting for: Product Owner
Dominant language
Python
Stars
4.3k
Forks
378
Avg merge
4d 1h
Merged PRs (30d)
1

Description

Hey folks,

We're trying to update some libs and hit an odd issue with updating responses. Consider this test:

```
import responses
import requests
from cachecontrol import CacheControl

def get_client():
return CacheControl(requests.Session())

@responses.activate
def test_with_cachecontrol():
client = get_client()
responses.add(responses.GET, "http://test-website.com", body="Hello, world!")

response = client.get("http://test-website.com")
assert response.text == "Hello, world!"

# force a connection error. Though since we're cached, it should return the cached response.
responses.add(responses.GET, "http://test-website.com", body=ConnectionError())
response = client.get("http://test-website.com")
assert response.text == "Hello, world!"
```

(This is a simplified version of the test in our code, but should suffice.)

The gist here is we use responses to force a valid response, then after we try to force it to instead raise a ConnectionError. Normally this would lead to the cached version of the data coming back. However once we go to reponses==0.25.8 from where we previously were in responses=0.12.1 this no longer works. We get the ConnectionError raised instead of getting the cached response.

I think responses isn't running the adapters that are otherwise on the session anymore. Is there a way to still run them for this type of testing?

If it helps, heres some more info about dependencies:

```
CacheControl=0.14.2
requests=2.32.4

python 3.12.6 on Mac
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.