Skip to content
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

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

Open
tmh-azinhal opened this issue Nov 3, 2020 · 4 comments
Open

Comments

@tmh-azinhal
Copy link

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
Copy link

belkka commented Nov 5, 2021

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

@belkka
Copy link

belkka commented Nov 5, 2021

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 MobileDynasty/pytest-env#3

@quiqua
Copy link
Owner

quiqua commented Nov 5, 2021

Thanks! I can try to look into this.

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

@major-mayer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants