Skip to content

Commit d24aad5

Browse files
committed
fix tests
1 parent ff26f78 commit d24aad5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

‎tests/serializers/test_model.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from pydantic_core import (
1717
PydanticSerializationError,
18-
PydanticSerializationUnexpectedValue,
1918
SchemaSerializer,
2019
SchemaValidator,
2120
core_schema,
@@ -1150,8 +1149,6 @@ class BModel(BasicModel): ...
11501149
)
11511150
)
11521151

1153-
with pytest.raises(
1154-
PydanticSerializationUnexpectedValue, match='Expected 2 fields but got 1 for type `.*AModel` with value `.*`.+'
1155-
):
1152+
with pytest.warns(UserWarning, match='Expected 2 fields but got 1 for type `.*AModel` with value `.*`.+'):
11561153
value = BasicModel(root=AModel(type='a'))
11571154
s.to_python(value)

‎tests/serializers/test_union.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dataclasses
22
import json
3-
import re
43
import uuid
4+
import warnings
55
from decimal import Decimal
66
from typing import Any, ClassVar, Union
77

@@ -32,9 +32,17 @@ def test_union_bool_int(input_value, expected_value, bool_case_label, int_case_l
3232

3333
def test_union_error():
3434
s = SchemaSerializer(core_schema.union_schema([core_schema.bool_schema(), core_schema.int_schema()]))
35-
msg = "Expected `Union[bool, int]` but got `str` with value `'a string'` - serialized value may not be as expected"
36-
with pytest.warns(UserWarning, match=re.escape(msg)):
37-
assert s.to_python('a string') == 'a string'
35+
36+
messages = [
37+
"Expected `bool` but got `str` with value `'a string'` - serialized value may not be as expected",
38+
"Expected `int` but got `str` with value `'a string'` - serialized value may not be as expected",
39+
]
40+
41+
with warnings.catch_warnings(record=True) as w:
42+
warnings.simplefilter('always')
43+
s.to_python('a string')
44+
for m in messages:
45+
assert m in str(w[0].message)
3846

3947

4048
class ModelA:

0 commit comments

Comments
 (0)