Skip to content

Commit

Permalink
update lifespan to be an async context manager
Browse files Browse the repository at this point in the history
generator lifespans were deprectated in starlette 0.16.0
https://github.com/encode/starlette/releases/tag/0.16.0
  • Loading branch information
meshantz committed Nov 5, 2021
1 parent 524abdc commit f5f1bfc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/test_router_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ def sub_router_shutdown():


def test_app_lifespan_state(state):
def lifespan(app):
state.app_startup = True
yield
state.app_shutdown = True

app = FastAPI(lifespan=lifespan)
class Lifespan:
def __init__(self, app):
pass
async def __aenter__(self):
state.app_startup = True
async def __aexit__(self, exc_type, exc_value, exc_tb):
state.app_shutdown = True

app = FastAPI(lifespan=Lifespan)

@app.get("/")
def main():
Expand Down

0 comments on commit f5f1bfc

Please sign in to comment.