new_callable arg to unittest.mock.patch seems not to support partial
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
As in the title. The following code seems to disregard the partial and proceed to call the wrapped function right away (instead of calling the wrapping partial object).
from functools import partial
from unittest.mock import patch
def wrapped():
"""an exemplary response from `some.directory.module.my_function` function"""
return [
{
"some_key": "some_value",
}]
def test_some_func():
with patch(
"some.directory.module.my_function", new_callable=partial(wrapped)
):
# calls `my_function` internally
some.directory.module.another_function()
Running the above will produce: TypeError: 'list' object is not callable.
Acc. to the docs an object passed as new_callable argument should be called by patch to create a new dummy object replacing the target (some.directory.module.my_function). However it seems that instead of partial being called and returning a wrapped function, a wrapped function itself is called returning the list.
CPython versions tested on:
3.11
Operating systems tested on:
macOS
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 unittest.mock.patch 入口点及其对 new_callable 的处理开始,使用报告中的 partial(wrapped) 复现用例。将观察到的调用序列与文档所述的契约进行比较,然后添加或更新回归覆盖,使 target 被预期的 callable 行为所替代。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100