The only problem I'm facing is how can test the function locally or even on my CI pipeline on the repo, as secretmanager.SecretManagerServiceClient() is trying to connect to Secret Manager service as soon as I import my main.py file on main_test.py file, and I don't have any GCP auth credentials on the environment.
Not sure if there is a way to mock up the client without changing the whole structure.
Thanks for the post! It has been very useful!
The only problem I'm facing is how can test the function locally or even on my CI pipeline on the repo, as
secretmanager.SecretManagerServiceClient()
is trying to connect to Secret Manager service as soon as I import mymain.py
file onmain_test.py
file, and I don't have any GCP auth credentials on the environment.Not sure if there is a way to mock up the client without changing the whole structure.
Thanks again!
Hi Sergio, I'd advise monkey-patching the
SecretManagerServiceClient
to something you can use in your tests.For example, if you use the pretend for stubbing, it could be something like: