facebook / facebook/TestSlide

Can't mock a @property without calling it?

Đang mở
#339 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
149
Fork
62
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**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")
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.