Skip to content
Discussion options

You must be logged in to vote

So far, the only idea I can come up with is writing a create_app function which selectively adds everything:

def create_app(environment: str = os.getenv("ENVIRONMENT")):
    app = FastAPI()

    # Don't register events and middleware relating to the database while testing.
    # Event handlers don't seem to run during testing anyway but we'll do this to be sure.
    if environment != "testing":
        app.add_event_handler("startup", startup)
        app.add_event_handler("shutdown", shutdown)
        app.add_middleware(BaseHTTPMiddleware, database_middleware)

    api_router = APIRouter()
    api_router.include_router(events.router, prefix="/events", tags=["events"])
    # ...

    app.i…

Replies: 23 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
6 participants
Converted from issue

This discussion was converted from issue #582 on February 28, 2023 11:59.