Skip to content

Commit 25694f5

Browse files
dmontagupre-commit-ci[bot]tiangolo
authored
✅ Fix tests for compatibility with pydantic 2.1.1 (fastapi#9943)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sebastián Ramírez <[email protected]>
1 parent 94c48cf commit 25694f5

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
id: cache
2626
with:
2727
path: ${{ env.pythonLocation }}
28-
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v03
28+
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v04
2929
- name: Install Dependencies
3030
if: steps.cache.outputs.cache-hit != 'true'
3131
run: pip install -r requirements-tests.txt
@@ -54,7 +54,7 @@ jobs:
5454
id: cache
5555
with:
5656
path: ${{ env.pythonLocation }}
57-
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v03
57+
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}-test-v04
5858
- name: Install Dependencies
5959
if: steps.cache.outputs.cache-hit != 'true'
6060
run: pip install -r requirements-tests.txt

tests/test_filter_pydantic_sub_model_pv2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Optional
22

33
import pytest
4-
from dirty_equals import IsDict
4+
from dirty_equals import HasRepr, IsDict
55
from fastapi import Depends, FastAPI
66
from fastapi.exceptions import ResponseValidationError
77
from fastapi.testclient import TestClient
@@ -66,7 +66,7 @@ def test_validator_is_cloned(client: TestClient):
6666
"loc": ("response", "name"),
6767
"msg": "Value error, name must end in A",
6868
"input": "modelX",
69-
"ctx": {"error": "name must end in A"},
69+
"ctx": {"error": HasRepr("ValueError('name must end in A')")},
7070
"url": match_pydantic_error_url("value_error"),
7171
}
7272
)

tests/test_multi_body_errors.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_jsonable_encoder_requiring_error():
5151
"loc": ["body", 0, "age"],
5252
"msg": "Input should be greater than 0",
5353
"input": -1.0,
54-
"ctx": {"gt": 0.0},
54+
"ctx": {"gt": "0"},
5555
"url": match_pydantic_error_url("greater_than"),
5656
}
5757
]
@@ -84,9 +84,23 @@ def test_put_incorrect_body_multiple():
8484
"input": {"age": "five"},
8585
"url": match_pydantic_error_url("missing"),
8686
},
87+
{
88+
"ctx": {"class": "Decimal"},
89+
"input": "five",
90+
"loc": ["body", 0, "age", "is-instance[Decimal]"],
91+
"msg": "Input should be an instance of Decimal",
92+
"type": "is_instance_of",
93+
"url": match_pydantic_error_url("is_instance_of"),
94+
},
8795
{
8896
"type": "decimal_parsing",
89-
"loc": ["body", 0, "age"],
97+
"loc": [
98+
"body",
99+
0,
100+
"age",
101+
"function-after[to_decimal(), "
102+
"union[int,constrained-str,function-plain[str()]]]",
103+
],
90104
"msg": "Input should be a valid decimal",
91105
"input": "five",
92106
},
@@ -97,9 +111,23 @@ def test_put_incorrect_body_multiple():
97111
"input": {"age": "six"},
98112
"url": match_pydantic_error_url("missing"),
99113
},
114+
{
115+
"ctx": {"class": "Decimal"},
116+
"input": "six",
117+
"loc": ["body", 1, "age", "is-instance[Decimal]"],
118+
"msg": "Input should be an instance of Decimal",
119+
"type": "is_instance_of",
120+
"url": match_pydantic_error_url("is_instance_of"),
121+
},
100122
{
101123
"type": "decimal_parsing",
102-
"loc": ["body", 1, "age"],
124+
"loc": [
125+
"body",
126+
1,
127+
"age",
128+
"function-after[to_decimal(), "
129+
"union[int,constrained-str,function-plain[str()]]]",
130+
],
103131
"msg": "Input should be a valid decimal",
104132
"input": "six",
105133
},

0 commit comments

Comments
 (0)