facebook / facebook/TestSlide

Prevent patch_attribute from patching instance attributes at classes

未关闭
#224 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement patch_attribute
主要语言
Python
星标
149
派生
62
PR 合并指标
30 天内没有已合并 PR

描述

This:

```python
import testslide

class A:
def __inti__(self):
self.attr = 1

class TestA(testslide.TestCase):
def test_attr(self):
self.patch_attribute(A, "attr", "mock")
```

yields:

```
AttributeError: type object 'A' has no attribute 'attr'
```

However, patching instance attributes at classes should not be allowed. `mock_callable` already [prevents](https://github.com/facebookincubator/TestSlide/blob/master/testslide/mock_callable.py#L601-L607) that.

Let's make patch_attribute refuse to patch instance attributes at classes as well.

Probably a good idea to reuse logic from `mock_callable` to define if "is this good to patch?".

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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