Skip to content

Commit e7412fe

Browse files
committed
Allow RuntimeError on older Python
Python < 3.12 wraps errors in __set_name__ in a RuntimeError. I've updated the test accordingly. We now test that either the exception is the expected one, or that the expected exception is the direct cause.
1 parent 1717088 commit e7412fe

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/test_properties.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,30 @@ class BasicThing(Thing):
7171
assert issubclass(BasicThing.prop.model, BaseModel)
7272

7373

74+
def exception_is_or_is_caused_by(err: Exception, cls: type[Exception]):
75+
return isinstance(err, cls) or isinstance(err.__cause__, cls)
76+
77+
7478
def test_instantiation_with_type_and_model():
7579
"""If a model is specified, we check it matches the inferred type."""
7680

7781
class BasicThing(Thing):
7882
prop = ThingProperty[bool](model=bool, initial_value=False)
7983

80-
with pytest.raises(MismatchedTypeError):
84+
with pytest.raises(Exception) as e:
8185

8286
class InvalidThing(Thing):
8387
prop = ThingProperty[bool](model=int, initial_value=False)
8488

85-
with pytest.raises(MissingTypeError):
89+
assert exception_is_or_is_caused_by(e.value, MismatchedTypeError)
90+
91+
with pytest.raises(Exception) as e:
8692

8793
class InvalidThing(Thing):
8894
prop = ThingProperty(model=bool, initial_value=False)
8995

96+
assert exception_is_or_is_caused_by(e.value, MissingTypeError)
97+
9098

9199
def test_missing_default():
92100
"""Test that a default is required if no model is specified."""

0 commit comments

Comments
 (0)