quiqua / pytest-dotenv

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

pytest-dotenv with pytest instead of py.test does not allow cli args #19

Open tmh-azinhal opened 3 years ago

tmh-azinhal commented 3 years ago

If pytest is used pytest-dotenv will only load an environment file from the pytest.ini. If py.test is used then the cli arg --envfile will be used.

pytest --envfile <path to .env> does nothing and will fallback to the config given in pytest.ini

belkka commented 2 years ago

I have tested this and for me

$ pip freeze | grep pytest-dot
pytest-dotenv==0.5.2
belkka commented 2 years ago

Looks like this is because .env is loaded by default if env_files is not specified in pytest.ini. And --envfile=my.env looks for me like being ignored because I am testing django. env_files from ini file are loaded before django configuration which goes before handling command line option --envfile. That's why django settings don't see values set via --envfile. Similar problem was discussed in https://github.com/MobileDynasty/pytest-env/issues/3

quiqua commented 2 years ago

Thanks! I can try to look into this.

Do you by chance have a minimal setup example that I can try @belkka ?

major-mayer commented 9 months ago

I can confirm that this still doesn't work. Specifying the .env.local file in the pyproject.toml works just fine, but not via the command line. I have no minimal setup for you, but you can execute something like this: python -m pytest -p vscode_pytest --collect-only --envfile .env.local tests