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
{{ message }}
This repository has been archived by the owner on Dec 26, 2021. It is now read-only.
I would like to be able to update configuration during unit tests.
(It could be handy to be able to do it outside of tests too ? (or maybe not))
What do we currently have to do now?
Now we can get config with config() helper but not set it.
Solutions I have in mind: Solution 1/
frommasonite.helpersimportset_configset_config("application.name", "Brand new name !")
Solution 2/
We can change environment loaded during tests, but changing env vars during a unit test does not change the config and the config() function still returns the same value.
Solution 3/
Create a Configuration provider, load it early in the app lifecycle and load in it configuration settings defined in config/,
the config helper would fetch settings from the configuration provider instead. settings would be maybe cached inside it to avoid accessing params from config files again.
Then it would be possible to set a config value because values would be hold inside this provider.
Yeah I was thinking about the last one actually (the most difficult lol).
But that's not the priority, this rewrite is just an occasion to think about it
I'm gonna close this for now. I think the simpler approach is to structure the app to pull from environment variables and then just set them in some kind of testing environment or the .env.testing file
I would like to be able to update configuration during unit tests.
(It could be handy to be able to do it outside of tests too ? (or maybe not))
What do we currently have to do now?
Now we can get config with config() helper but not set it.
Solutions I have in mind:
Solution 1/
Solution 2/We can change environment loaded during tests, but changing env vars during a unit test does not change the config and the config() function still returns the same value.
Solution 3/
Create a Configuration provider, load it early in the app lifecycle and load in it configuration settings defined in
config/
,the config helper would fetch settings from the configuration provider instead. settings would be maybe cached inside it to avoid accessing params from config files again.
Then it would be possible to set a config value because values would be hold inside this provider.
Solution 4/
As this would be mostly used during unit tests, maybe we can call "something" in
setUp()
to load a different configuration ?Temporary workaround
Totally open about this !
The idea is to be able to as in Laravel
https://laravel.com/docs/master/configuration#accessing-configuration-values
and Django
https://docs.djangoproject.com/en/3.1/topics/testing/tools/#overriding-settings
The text was updated successfully, but these errors were encountered: