MobileDynasty / pytest-env

pytest plugin used to set environment variables
MIT License
217 stars 23 forks source link

keyerror in TOX #14

Open JeffWScott opened 5 years ago

JeffWScott commented 5 years ago

I'm not sure why it's so hard to get system environmental variables into TOX. I mean, how else do you use secret API keys in a shared environment (ie, not cloning them to github).

So I came across pytest-env because it looked exactly like I want, but it doesn't seem to be as easy as your readme would have me believe.

This is my pytest.ini

[pytest]
env =
    API_KEY={API_KEY}

In my conftest.ini I use it like this.

key = os.environ['API_KEY']

running tox gives me this error

  File "/mnt/e/Lamden/clove/.tox/python/lib/python3.6/site-packages/pytest_env/plugin.py", line 32, in pytest_load_initial_conftests
    value = value.format(**os.environ)
KeyError: 'API_KEY'

What do you think I'm doing wrong?

newinh commented 4 years ago

it seems to weird using python syntax in ini file.

i'm not sure about tox and conftest.ini, i suggest appropriate syntax for file format.

if use conftest.ini

key = {API_KEY}

or in conftest.py

key = os.environ['API_KEY']
gaborbernat commented 1 year ago

Development moved to https://github.com/pytest-dev/pytest-env