-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
requireFile option for strict checking of env file existence #297
Comments
#245 this added a warning output if verbose is true, which can help with visibility but doesn't address the issue if you want a strict requirement on config file existence. |
Hey bro, I’m happy to see you have the same opinion with me, but somehow the author does not like this idea, I think you can just fork this repo for your personal use, or just include this single file library as a module of your project/package like I did. I don’t want to be mean here, but this is actually a very simple suggestion with straight forward solution, if he didn’t take my suggestion, he won’t take yours either, I almost feel sorry for you, I just cannot unsee warm-hearted people who want to make reasonable contributions being ignored 😔 |
This would be useful. For projects heavily relying on environment configuration, such as Kubernetes applications, it may prove useful to ensure the environment has been correctly loaded prior to running tests. For an app I may have, for example, a few environment files such as I had initially assumed def pytest_configure(*_):
x = load_dotenv(Path("gibberish") / "tests.env", override=True) gives me It would be perfectly sufficient if it returned False, which seems like a less intrusive option if the new parameter does not suit everyone's needs. |
We have a similar request here: I like the approach of using exceptions after passing an additional parameter,
@guhcampos This is now added to the latest code. (Not released yet). |
Looks like something related was implemented in #388 Instead of the |
Also there isn't a warning if Verbose is on and the file doesn't exist:
|
In some scenarios (say if you want clear deterministic behaviour for a production app) it is desirable to immediately fail with an obvious error if the specified env file is absent, instead of starting the application in a potentially problematic way due to missing configuration. Clear behaviour, explicit requirements, and obvious failures are important to avoid fragile situations, such as an app working in production by accidentally getting the right config from an unexpected place. Maybe later you clean up other files that you think aren't needed, but then the app breaks because it was not actually getting the config from where you thought it was.
There have been several issues discussing this (both in dotenv and downstream environs):
raise_error_if_not_found
for read_env sloria/environs#165To provide a solution for these types of problems, I propose a new option, something like "requireFile", for load_dotenv. It can be false by default to preserve current behaviour. @theskumar
If true, it would enable a strict file existence requirement for load_dotenv , so that it fails if no env file is found, no matter how/where (whether it is a named one specified by dotenv_path, or the default ".env" or found by recursing directories ).
And the behaviour of how/where env files are found would remain unchanged. Would that be a reasonable way to address this?
The text was updated successfully, but these errors were encountered: