Skip to content

Commit 7005a7e

Browse files
Add test for cached property error case (#264)
* Add test for cached property error case * Update tests/test_property.py Co-authored-by: Matthieu Dartiailh <marul@laposte.net> --------- Co-authored-by: Matthieu Dartiailh <marul@laposte.net>
1 parent 4d63def commit 7005a7e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tests/test_property.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ def set(self, value):
160160
p.setter(set)
161161

162162

163+
def test_cached_property_error():
164+
"""Test using a cached property that returns an error."""
165+
v = 0
166+
167+
class Obj(Atom):
168+
def _get_x(self):
169+
nonlocal v
170+
v += 1
171+
if v & 1:
172+
raise ValueError("get_x failed!")
173+
return v
174+
175+
x = Property(_get_x, cached=True)
176+
177+
o = Obj()
178+
with pytest.raises(ValueError) as excinfo:
179+
o.x # This puts null in the slot
180+
assert "get_x failed" in excinfo.exconly()
181+
assert o.x == 2
182+
assert o.x == 2
183+
184+
163185
def test_observed_property():
164186
"""Test observing a property."""
165187

0 commit comments

Comments
 (0)