HACKER Q&A
📣 zikohh

Is there Python package that can read environment variables


pytest-mongodb https://github.com/mdomke/pytest-mongodb#migration-from-humongous requires 3 variables to be defined in pytest.ini these variables are already used in the code as environment variables. It doesn't make sense to duplicate the code in pytest.ini

I saw that https://pypi.org/project/pytest-env/ let's you define environment variables but this isn't very intelligent since it's only one way. I want it to read and in pytest.ini e.g

[pytest] x=$blah

Are there any packages that can do this?


  👤 Godel_unicode Accepted Answer ✓
You can read environment variables via os in the cpython standard library: os.environ["VARIABLE_NAME"]