Can't mock a @property without calling it?
- Dominant language
- Python
- Stars
- 149
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
**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")
```
Contributor guide
Assessment
This issue has not been assessed yet.