Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

How to use responses with cachecontrol?

未关闭
#780 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
testing-qa

调研方向

首先使用 responses 0.25.8、CacheControl 0.14.2、requests 2.32.4 和 Python 3.12.6 运行提供的测试,然后将其与 responses 0.12.1 进行比较。跟踪 responses 如何处理 requests Session 及其适配器;当强制连接错误返回复现中所示的先前缓存的响应时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug Waiting for: Product Owner

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
主要语言
Python
星标
4.3k
派生
389
平均合并
1 天 17 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

getsentry/responses 的其他 Issue

查看 getsentry/responses 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。