When mocking with `unsafe=True` the mocked instances don't receive the unsafe argument.

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

还没有人认领这个 Issue。

评估

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

调研方向

从创建 Klass 实例的 _patch 类及其 enter 方法入手,检查 unsafe 是如何传递给 Mock 的。更新相关测试用例,以展示 unsafe=True 会传递到被 mock 的实例,并且它们的内部 unsafe 状态会相应发生变化。

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

描述

stdlib type-bug

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
主要语言
Python
星标
77.2k
派生
36k
平均合并
1 天 9 小时
30 天内合并 PR
558

贡献指南

打开贡献指南

从这里开始

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

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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