Browse Source
docs: catch startup deprecated warning
pull/13259/head
z0z0r4
3 weeks ago
No known key found for this signature in database
GPG Key ID: 448EF3037425FD6A
1 changed files with
8 additions and
4 deletions
-
docs_src/app_testing/tutorial003.py
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
import warnings |
|
|
from fastapi import FastAPI |
|
|
from fastapi import FastAPI |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
|
|
@ -5,11 +6,14 @@ app = FastAPI() |
|
|
|
|
|
|
|
|
items = {} |
|
|
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") |
|
|
@app.on_event("startup") |
|
|
async def startup_event(): |
|
|
async def startup_event(): |
|
|
items["foo"] = {"name": "Fighters"} |
|
|
items["foo"] = {"name": "Fighters"} |
|
|
items["bar"] = {"name": "Tenders"} |
|
|
items["bar"] = {"name": "Tenders"} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/items/{item_id}") |
|
|
@app.get("/items/{item_id}") |
|
|