Open tmh-azinhal opened 3 years ago
I have tested this and for me
pytest --envfile=my.env
ignores my.env
file and uses .env
instead.py.test
works the same way, no differences.$ pip freeze | grep pytest-dot
pytest-dotenv==0.5.2
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
Thanks! I can try to look into this.
Do you by chance have a minimal setup example that I can try @belkka ?
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
If
pytest
is used pytest-dotenv will only load an environment file from thepytest.ini
. Ifpy.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 inpytest.ini