Skip to content

Commit 369faaa

Browse files
committed
Fix tests for Python < 3.12
Exceptions raised during class definition are wrapped in a RuntimeError prior to Python 3.12, so I use `raises_or_is_called_by` to check the error. It's not ideal that our error gets wrapped in a RuntimeError, but there's relatively little we can do about it.
1 parent cc3cb27 commit 369faaa

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

tests/test_base_descriptor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def test_fieldtyped_definition(name, value_type):
332332

333333
def test_fieldtyped_missingtype():
334334
"""Check the right error is raised when no type can be found."""
335-
with pytest.raises(MissingTypeError) as excinfo:
335+
with raises_or_is_caused_by(MissingTypeError) as excinfo:
336336

337337
class Example2:
338338
field2 = FieldTypedBaseDescriptor()
@@ -405,7 +405,7 @@ class Example3:
405405

406406
# Rather than roll my own evaluator for forward references, we just
407407
# won't support forward references in subscripted types for now.
408-
with pytest.raises(MissingTypeError) as excinfo:
408+
with raises_or_is_caused_by(MissingTypeError) as excinfo:
409409

410410
class Example4:
411411
field6 = FieldTypedBaseDescriptor["str"]()
@@ -418,7 +418,7 @@ class Example4:
418418

419419
def test_mismatched_types():
420420
"""Check two type hints that don't match raises an error."""
421-
with pytest.raises(InconsistentTypeError):
421+
with raises_or_is_caused_by(InconsistentTypeError):
422422

423423
class Example3:
424424
field: int = FieldTypedBaseDescriptor[str]()
@@ -445,7 +445,7 @@ def test_stringified_vs_unstringified_mismatch():
445445
If a descriptor is typed using both a subscript and a field
446446
annotation, they should match -
447447
"""
448-
with pytest.raises(InconsistentTypeError):
448+
with raises_or_is_caused_by(InconsistentTypeError):
449449

450450
class Example5:
451451
field: "int" = FieldTypedBaseDescriptor[int]()

tests/test_property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_baseproperty_type_and_model():
155155
`pydantic.RootModel`.
156156
"""
157157

158-
with pytest.raises(tp.MissingTypeError):
158+
with raises_or_is_caused_by(tp.MissingTypeError):
159159

160160
class Example:
161161
prop = tp.BaseProperty()

0 commit comments

Comments
 (0)