Closed mpessas closed 6 years ago
I was trying pytest-dotenv and noticed that the variables I would define in the .env file used for testing would not override the ones already defined by docker-compose. This creates a problem for me, given that the goal is exactly that: have tests run with their own set of variables no matter what is or is not in the environment already.
So in your docker-compose you have something like:
my-app:
env_file:
- production.env
And your container also contains a .env
file which has different contents, so you want to override them?
Or do you configure them via:
my-app:
environment:
- FOO=bar
Also this seems somehow related: https://stackoverflow.com/questions/29062522/different-env-file-but-same-yml-with-docker-compose#comment80776332_29063882
I'll just try to understand your use-case a bit further: are you just running the tests when you trigger docker-compose up|start
?
I do docker-compose run --rm <container> pytest
. The docker-compose file defines its own set of variables, which I'd like to override for the test suite.
I still used the prefix env_
as a namespace, so as to avoid any name collision with other plugins.
The commit instructs dotenv to override any variables that already exist in the environment, so that the ones we define for pytest take precedence over any defaults defined e.g. in a docker-based setup.