pythonpython-3.xtestingenvironment-variablespytest

Best way to use python-dotenv with pytest, or best way to have a pytest test/dev-environment with seperate configs


I want to use the python dotenv-lib at my python project. My dev-environment should use .env-file and the test-suite (pytest) should use .env.test automatically.

Until now I didn't find a satisfying solution.

I'm not very familiar with python. Maybe somebody can point me in the right direction.

Should I load the .env.test file in a pytest hook?


Solution

  • For anyone coming in 2019 or later:

    You can use pytest-dotenv 😉.