Fastapi - run a function with dependencies outside of request

3k Views Asked by At

I have two functions that my code Depends on, also the second one depends on the first.

def get_db() -> Iterable[sessionmaker]:
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

def get_someservice(db: Session = Depends(get_db)) -> SomeService:
    return SomeService(db)

Now in my tests I'd like to test SomeService but without making any requests to the app. I also want fastapi to provide the dependency.

I can't just do get_someservice(). Is there a call_function_and_provide_dependencies(get_someservice) of some sort?

0

There are 0 best solutions below