Closed setu4993 closed 3 years ago
The first option works for me
env = [
"environment=test",
"api_key=foo"
]
@nermand : Interesting. It still doesn't work for me. I'm probably doing something wrong.
pyproject.toml
:
...
[tool.pytest.ini_options]
env = [
"environment=test",
"api_key=foo"
]
test_env.py
:
from os import environ
def test_env_environment():
assert environ["environment"] == "test"
def test_env_api_key():
assert environ["api_key"] == "foo"
FWIW I am using python-dotenv
for loading .env variables.
Not sure if that affects how envs are parsed
No luck even after adding python-dotenv
and pytest-dotenv
for me :/.
@setu4993
The following works for me, and I'm not using python-dotenv
:
[tool.pytest.ini_options]
env = '''
HOME=~/tmp
RUN_ENV=test
'''
Thanks @nermand and @bosatsu! Good pointers. I can confirm that any of the below work without python-dotenv
or pytest-dotenv
:
1.
[tool.pytest.ini_options]
env = [
"HOME=~/tmp",
"RUN_ENV=test"
]
[tool.pytest.ini_options]
env ="HOME=~/tmp\nRUN_ENV=test"
[tool.pytest.ini_options]
env = """
HOME=~/tmp
RUN_ENV=test
"""
If it doesn't recommend rechecking the pytest version. My pytest
version was downgraded to <6.0, without me noticing, and since pyproject.toml
support was added in 6.0+, it wasn't working.
Thanks for creating and maintaining this package!
Can you please provide an example of using this library with
pyproject.toml
files that pytest config supports? Neither of the below work. 1:2: