pytest-bdd
pytest-bdd copied to clipboard
Implement parametrization through excel sheets based on the input arguments
trafficstars
My Scenario is parameterized and I want to select the parameter value from EXCEL. I want to select sheets in the excel based on environment provided qa,uat,prod .Is there any way to dynamically select sheet value to run the parameterised tests.
Scenario: Verify Licenses
Given the <user> is logged in with <password>
Then the response should show <status>
Referring to the issue @ https://github.com/pytest-dev/pytest/issues/6374, I have added the following
In conftest.py
def pytest_addoption(parser):
parser.addoption('--env',
dest='testenv',
choices=["qa","uat","prod"],
default='qa',
help='Specify environment:"qa", "uat", "prod"')
@lru_cache(maxsize = 128)
def get_env(env):
wbinput = openpyxl.load_workbook('iban/data/Licenses.xlsx')
sheetip= wbinput[env] # sheet to select based on env
maxRow=sheetip.max_row
inputData = [tuple(sheetip.cell(row=i,column=j).value for j in range(1,3)) for i in range(2,maxRow+1)]
return inputData
# this code doesnot suite me, as I have no markers for my scenario. My scenario should run for all env values but take the correponding env value for each env.
def pytest_generate_tests(metafunc):
if "env" in metafunc.fixturenames:
metafunc.parametrize("env", get_env(metafunc.config.getoption("env")))
Any help is much appreciated.