What's the right way to mock on_startup
callbacks?
#3944
dan-jacobson
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When I'm trying to test my app, I have an
on_startup
callback to connect to a DB. It looks roughly like the example.However, how can I test it? There's times I want to run my tests without the actual DB connection, and so I try to mock it out. The best I can come up with is:
This kinda feels hacky. Is there a better way to just directly mock or patch the
get_db_connection()
call? I tried all the variants ofpatch("app.app.on_startup")
andpatch("app.app.get_db_connection")
I could think of.How do other folks handle this?
Beta Was this translation helpful? Give feedback.
All reactions