|
1 | | -import pytest |
2 | 1 | from fastapi import FastAPI |
3 | 2 | from fastapi.testclient import TestClient |
4 | 3 |
|
5 | 4 | from .utils import skip_py38 |
6 | 5 |
|
7 | 6 |
|
8 | 7 | @skip_py38 |
9 | | -@pytest.mark.parametrize( |
10 | | - "test_type,expect", |
11 | | - [ |
12 | | - (list[int], [1, 2, 3]), |
13 | | - (dict[str, list[int]], {"a": [1, 2, 3], "b": [4, 5, 6]}), |
14 | | - (set[int], {1, 2, 3}), |
15 | | - (tuple[int], (1, 2, 3)), |
16 | | - ], |
17 | | -) |
18 | | -def test_typing(test_type, expect): |
19 | | - app = FastAPI() |
| 8 | +def test_typing(): |
| 9 | + types = { |
| 10 | + list[int]: [1, 2, 3], |
| 11 | + dict[str, list[int]]: {"a": [1, 2, 3], "b": [4, 5, 6]}, |
| 12 | + set[int]: [1, 2, 3], # `set` is converted to `list` |
| 13 | + tuple[int, ...]: [1, 2, 3], # `tuple` is converted to `list` |
| 14 | + } |
| 15 | + for test_type, expect in types.items(): |
| 16 | + app = FastAPI() |
20 | 17 |
|
21 | | - @app.get("/", response_model=test_type) |
22 | | - def get_endpoint(): |
23 | | - return expect |
| 18 | + @app.post("/", response_model=test_type) |
| 19 | + def post_endpoint(input: test_type): |
| 20 | + return input |
24 | 21 |
|
25 | | - res = TestClient(app).get("/") |
26 | | - assert res.status_code == 200 |
27 | | - assert res.json() == expect |
| 22 | + res = TestClient(app).post("/", json=expect) |
| 23 | + assert res.status_code == 200, res.json() |
| 24 | + assert res.json() == expect |
0 commit comments