Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbdd4b9

Browse files
committed
fix tests
1 parent 7f329e2 commit cbdd4b9

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

tests/test_typing_python39.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import pytest
21
from fastapi import FastAPI
32
from fastapi.testclient import TestClient
43

54
from .utils import skip_py38
65

76

87
@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()
2017

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
2421

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

tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
import pytest
44

55
skip_py36 = pytest.mark.skipif(sys.version_info < (3, 7), reason="skip python3.6")
6-
skip_py38 = pytest.mark.skipif(sys.version_info < (3, 9), reason="skip python 3.8")
6+
skip_py38 = pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9")

0 commit comments

Comments
 (0)