Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement parametrization through excel sheets based on the input arguments #364

Open
CuriousQA opened this issue Jun 2, 2020 · 0 comments

Comments

@CuriousQA
Copy link

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 @ pytest-dev/pytest#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant