You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because the loading happens at the top level of the module, the ENV variable gets read in when the module is imported. In other words: we have no control over when the ENV variable is read in (e.g. during or after app startup).
This mainly matters during testing where we have to make sure we set ENV variables before the test run starts at all using something like https://pypi.org/project/pytest-env/ because by the time we have launched the TestApp client or imported the utility module any further changes to ENV variables will have no effect (because the reading has already happened).
This has two immediate consequences:
it's tricky / hard to actually test the reading of ENV variables (e.g. testing for several ENV values)
we need hard-to-fully-understand workarounds like monkeypatching the internal variable that the ENV value is read into
So we should look into better options
The text was updated successfully, but these errors were encountered:
surchs
transferred this issue from neurobagel/federation-api
May 28, 2024
We want to keep our issues up to date and active. This issue hasn't seen any activity in the last 75 days.
We have applied the _flag:stale label to indicate that this issue should be reviewed again.
When you review, please reread the spec and then apply one of these three options:
prioritize: apply the flag:schedule label to suggest moving this issue into the backlog now
close: if the issue is no longer relevant, explain why (give others a chance to reply) and then close.
archive: sometimes an issue has important information or ideas but we won't work on it soon. In this case
apply the someday label to show that this won't be prioritized. The stalebot will ignore issues with this
label in the future. Use sparingly!
os.env
read?For testing the time at which the env vars are read is at import time as opposed to at app start time/test runtime.
In the n-API (and soon f-API: neurobagel/federation-api#90) we load ENV variables in a utility module like so
api/app/api/utility.py
Lines 16 to 18 in 84c0e99
Because the loading happens at the top level of the module, the ENV variable gets read in when the module is imported. In other words: we have no control over when the ENV variable is read in (e.g. during or after app startup).
This mainly matters during testing where we have to make sure we set ENV variables before the test run starts at all using something like https://pypi.org/project/pytest-env/ because by the time we have launched the TestApp client or imported the utility module any further changes to ENV variables will have no effect (because the reading has already happened).
This has two immediate consequences:
So we should look into better options
The text was updated successfully, but these errors were encountered: