diff --git a/check_params.py b/check_params.py new file mode 100644 index 0000000000..df8719546d --- /dev/null +++ b/check_params.py @@ -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} diff --git a/docs_src/app_testing/tutorial003.py b/docs_src/app_testing/tutorial003.py index 45f6f678c6..3ff87cb2a7 100644 --- a/docs_src/app_testing/tutorial003.py +++ b/docs_src/app_testing/tutorial003.py @@ -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"} \ No newline at end of file + assert response.json() == {"name": "Fighters"} diff --git a/tests/test_tutorial/test_testing/test_tutorial003.py b/tests/test_tutorial/test_testing/test_tutorial003.py index bbadb296bb..b455bc949f 100644 --- a/tests/test_tutorial/test_testing/test_tutorial003.py +++ b/tests/test_tutorial/test_testing/test_tutorial003.py @@ -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()