When mocking with `unsafe=True` the mocked instances don't receive the unsafe argument.
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
描述
Bug report
When the feature Check against misspellings of assert etc. in mock was introduced, the unsafe flag was moved out from kwargs and defined as a named argument.
Previously since unsafe was implicitly part of kwargs, it was silently propagated from _patch class to the instantiation of the klass variable inside the __enter__ method.
But now, the unsafe flag as an explicitly named argument is not being propagated to the instantiation of the Klass variable.
Hence the Mock class is unable to set its internal attribute _mock_unsafe and will always be False regardless of whether the user set unsafe=True or not.
The test cases have to be updated to show this bug.
This bug was introduced in this commit: fdb9efce6ac211f973088eef508740c3fa2bd182 (bpo-41877) and only included in versions from Python 3.10.
Your environment
- CPython versions tested on: 3.10, 3.11 and master branch.
- Operating system and architecture: Ubuntu 22.04
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从创建 Klass 实例的 _patch 类及其 enter 方法入手,检查 unsafe 是如何传递给 Mock 的。更新相关测试用例,以展示 unsafe=True 会传递到被 mock 的实例,并且它们的内部 unsafe 状态会相应发生变化。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- testing-qa
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100