quiqua / pytest-dotenv

A py.test plugin that parses environment files before running tests
MIT License
189 stars 18 forks source link

Listing multiple .env files should source them sequentially even when env_override_existing_values is not set #22

Open maxmelamed opened 2 years ago

maxmelamed commented 2 years ago

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.

ikonst commented 2 years ago

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).