https://prefect.io logo
d

Deceivious

07/07/2023, 8:33 AM
Hi, Can someone help me override Settings context? Usecase: I have 3 profiles: 1. local_db [Connects to self hosted postgres database] 2. dev [Dev prefect api] 3. prod [Prod prefect api] In addition to that, I want a unit test profile which connects to a dockerized postgres. I do not want this to be a profile as the tests will be run on multiple machines - hence the need for a fresh Settings context. We cannot use the test harness as we need to run database queries. How do I initialize my own settings context without creating new profile?
There must be better ways that python native mock patch?
I ended up copying the test harness function and modifying it to suit my needs.
l

Luke Dolan

07/07/2023, 8:34 PM
Hey, is temporary settings what you're after? https://docs.prefect.io/2.10.18/api-ref/prefect/settings/#prefect.settings.temporary_settings
Copy code
>>> from prefect.settings import PREFECT_API_URL
>>>
>>> with temporary_settings(updates={PREFECT_API_URL: "foo"}):
>>>    assert PREFECT_API_URL.value() == "foo"
>>>
🙌 1
d

Deceivious

07/10/2023, 8:24 AM
THanks