facebook / facebook/TestSlide

Prevent patch_attribute from patching instance attributes at classes

Aperta
#224 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement patch_attribute
Lingua principale
Python
Stelle
149
Fork
62
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?".

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.