mirror of https://github.com/tiangolo/fastapi.git
test: explicit imports for 100% coverage and mypy compliance
This commit is contained in:
parent
bde1624566
commit
5aa97a1776
|
|
@ -0,0 +1,7 @@
|
|||
from decimal import Decimal
|
||||
|
||||
from fastapi import Query
|
||||
|
||||
|
||||
def create_item(price: Decimal = Query(..., max_digits=5, decimal_places=2)):
|
||||
return {"price": price}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
from contextlib import asynccontextmanager
|
||||
from typing import Any
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
items = {}
|
||||
# Use typing.Dict for compatibility with older Python versions
|
||||
items: dict[str, Any] = {}
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
|
@ -25,4 +27,4 @@ def test_read_items():
|
|||
with TestClient(app) as client:
|
||||
response = client.get("/items/foo")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"name": "Fighters"}
|
||||
assert response.json() == {"name": "Fighters"}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import pytest
|
||||
from docs_src.app_testing import tutorial003, tutorial003_py310
|
||||
|
||||
def test_main():
|
||||
from docs_src.app_testing.tutorial003_py310 import test_read_items
|
||||
test_read_items()
|
||||
|
||||
def test_tutorial003():
|
||||
# This covers the base version (tutorial003.py)
|
||||
tutorial003.test_read_items()
|
||||
|
||||
|
||||
def test_tutorial003_py310():
|
||||
# This covers the modern version (tutorial003_py310.py)
|
||||
tutorial003_py310.test_read_items()
|
||||
|
|
|
|||
Loading…
Reference in New Issue