on-internet
← Community

FastAPI TestClient overriding lifespan function

Stack Overflow ·

In a more complicated setup using the python dependency injector framework I use the lifespan function for the FastAPI app object to correctly wire everything. When testing I'd like to replace some of the objects with different versions (fakes), and the natural way to accomplish that seems to me like I should override or mock the lifespan function of the app object. However I can't seem to figure out if/how I can do that. MRE follows import pytest from contextlib import asynccontextmanager from fastapi.testclient import TestClient from fastapi import FastAPI, Response, status greeting = None @

Comments

Sign in or sign up to comment and upvote.

No comments yet.