From 28441fb701779749d3927e9e5d0848d99c842da0 Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Thu, 30 Apr 2026 13:38:02 -0400 Subject: [PATCH 1/2] Add test for cached property error case --- tests/test_property.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_property.py b/tests/test_property.py index b27fa4b7..ab7f91e9 100644 --- a/tests/test_property.py +++ b/tests/test_property.py @@ -160,6 +160,27 @@ 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() + assert o.x == v + + def test_observed_property(): """Test observing a property.""" From 6100fa025a72f675d8c5356e29b2de8de298c856 Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Wed, 6 May 2026 12:34:42 +0000 Subject: [PATCH 2/2] Update tests/test_property.py Co-authored-by: Matthieu Dartiailh --- tests/test_property.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_property.py b/tests/test_property.py index ab7f91e9..025f2e69 100644 --- a/tests/test_property.py +++ b/tests/test_property.py @@ -178,7 +178,8 @@ def _get_x(self): with pytest.raises(ValueError) as excinfo: o.x # This puts null in the slot assert "get_x failed" in excinfo.exconly() - assert o.x == v + assert o.x == 2 + assert o.x == 2 def test_observed_property():