pytest-dotenv
pytest-dotenv copied to clipboard
Listing multiple .env files should source them sequentially even when env_override_existing_values is not set
Hey there! I'm using this plugin and I've noticed the following behavior, which is somewhat confusing. If I have my pytest-dotenv config as follows:
env_files =
.env <-- defines FOOBAR=5
.env.test <-- defines FOOBAR=7
then I end up with FOOBAR=5
.
I understand this can be fixed with env_override_existing_values=1
, but the docs seem to suggest that this is intended for overriding existing env vars in the current process, rather than env vars in a previously listed file. In my opinion, it would make sense to overwrite values from previously specified env files by default, while leaving env_override_existing_values=1
for deciding whether or not existing env vars in the process should be overwritten.
I'd be happy to open a PR if the proposed behavior makes sense.
One thing to note is that'd be a breaking change, since currently the inverse would work (putting .env.test
first) and if you make that change, this will no longer be true. A possible solution is to make this a documented behavior (to list env files in reverse).