pytest-dev / pytest-dev/pytest-bdd

Implement parametrization through excel sheets based on the input arguments

Open
#364 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
251
Avg merge
43m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed conftest.py hooks, especially pytest_addoption and pytest_generate_tests, along with the Excel path iban/data/Licenses.xlsx. Clarify whether --env should select one sheet or whether each scenario should run against qa, uat, and prod; done means the intended environment selection works for the shown parameterized scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.