Before I start executing the tests in my Python project, I read some environment variables and set some variables with these values read. My tests will run on the desired en
There are few ways you can achieve this
If you dont want to use the environment variable , you can use pytest addoptions as https://docs.pytest.org/en/latest/example/simple.html
You can write a wrapper script like this to call enviornment variables
import os
import py
env_name = os.environ["ENV_NAME"]
env_no = os.environ["ENV_NUMBER"]
pytest_args=(env_name,env_no)
pytest.main('-s' ,pytest_args,test_file.py)
in test_file.py you can use
env_n, env_n = pytest.config.getoption('pytest_args')
on command line you can use it as
py.test --testdata ="ENV_NAME:staging,ENV_NUMBER:5"
You can use in your test file
pytest_params = pytest.config.getoption('testdata')
params = pytest_params.split(":")
param_dict = dict(params[i:i+2] for i in range(0,len(params),2))
env_name = param_dict["ENV_Name"]