After some investigation I came to the conclusion of not using python-dotenv. I ended up using the cool library simple-settings and pytest hooks. It solves my requirements quite well! simple-settings can load settings from several file-types. Which setting-file is loaded can be decided through an environment variable.
Following post can be very helpful, if somebody wants to learn something about pytest and its conftest file: In py.test, what is the use of conftest.py files?
Here's my conftest.py file with two hooks implemented:
import os
def pytest_configure(config):
os.environ['SIMPLE_SETTINGS'] = 'config.test'
return config
def pytest_unconfigure(config):
os.environ['SIMPLE_SETTINGS'] = 'config.development'
return config
If I run some test with pytest the corresponding environment variable is set. So my test-suite uses automatically the right settings.