I have a simple FastAPI setup as below,
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.on_event("shutdown")
def app_shutdown():
with open("shutdown-test-file.txt", "w") as fp:
fp.write("FastAPI app has been terminated")
@app.get("/")
def root():
return {"message": "Hello World"}
How can I write (unit)test for this app_shutdown(...)
functionality?
Related Posts
- This SO post is also asking similar question, but, not in a "testing context"
- The official doc has something similar, but, there is no example for
on_event("shutdown")