Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ def set(self, value):
p.setter(set)


def test_cached_property_error():
"""Test using a cached property that returns an error."""
v = 0

class Obj(Atom):
def _get_x(self):
nonlocal v
v += 1
if v & 1:
raise ValueError("get_x failed!")
return v

x = Property(_get_x, cached=True)

o = Obj()
with pytest.raises(ValueError) as excinfo:
o.x # This puts null in the slot
assert "get_x failed" in excinfo.exconly()
Comment on lines +178 to +180
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth accessing the value a second to exercise the caching behavior in presence of error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

assert o.x == 2
assert o.x == 2


def test_observed_property():
"""Test observing a property."""

Expand Down
Loading