From 1b4351e5e5dbf484a4f5d12caa1522d98ca1661d Mon Sep 17 00:00:00 2001 From: z0z0r4 Date: Tue, 15 Jul 2025 19:02:49 +0800 Subject: [PATCH] docs: catch startup deprecated warning --- docs_src/app_testing/tutorial003.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs_src/app_testing/tutorial003.py b/docs_src/app_testing/tutorial003.py index d1a943cce..782530a83 100644 --- a/docs_src/app_testing/tutorial003.py +++ b/docs_src/app_testing/tutorial003.py @@ -1,3 +1,4 @@ +import warnings from fastapi import FastAPI from fastapi.testclient import TestClient @@ -5,11 +6,14 @@ app = FastAPI() items = {} +# startup event and shutdown event are deprecated, you should use lifespan instead +with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) -@app.on_event("startup") -async def startup_event(): - items["foo"] = {"name": "Fighters"} - items["bar"] = {"name": "Tenders"} + @app.on_event("startup") + async def startup_event(): + items["foo"] = {"name": "Fighters"} + items["bar"] = {"name": "Tenders"} @app.get("/items/{item_id}")