facebook / facebook/TestSlide

Prevent patch_attribute from patching instance attributes at classes

オープン
#224 コメント 2 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。