facebook / facebook/TestSlide

Can't mock a @property without calling it?

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

Descrizione

**I'm using `TestSlide` version:** 2.7.0

**Given:**
```
import testslide

class SampleClass:
@property
def prop(self) -> str:
raise RuntimeError("must not be called")

def meth(self) -> str:
raise RuntimeError("must not be called")

class SampleTest(testslide.TestCase):
def test_prop_attr(self) -> None:
host = SampleClass()
self.patch_attribute(host, "prop", "patched")
self.assertEqual(host.prop, "patched")

def test_prop_callable(self) -> None:
host = SampleClass()
self.mock_callable(host, "prop").to_return_value("patched")
self.assertEqual(host.prop, "patched")

def test_meth(self) -> None:
host = SampleClass()
self.mock_callable(host, "meth").to_return_value("patched")
self.assertEqual(host.meth(), "patched")
```

**When I run:**
`testslide patch_test.py`

**I expected this to happen:**
`prop()` is not called

**But, instead this happened:**
`prop()` is called, both when using `patch_attribute` and `mock_callable`.

```
patch_test.SampleTest
test_meth
test_prop_attr: RuntimeError: must not be called
test_prop_callable: RuntimeError: must not be called

Failures:

1) patch_test.SampleTest: test_prop_attr
1) RuntimeError: must not be called
File "patch_test.py", line 15, in test_prop_attr
self.patch_attribute(host, "prop", "patched")
File "patch_test.py", line 6, in prop
raise RuntimeError("must not be called")

2) patch_test.SampleTest: test_prop_callable
1) RuntimeError: must not be called
File "patch_test.py", line 20, in test_prop_callable
self.mock_callable(host, "prop").to_return_value("patched")
File "patch_test.py", line 6, in prop
raise RuntimeError("must not be called")
```

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.