Tags(smoke/regression) to be passed from CLI and to be interpreted in conftest.py to execute those scenarios satisfying the tags.
I've looked into the pytest-bdd document here and failed to find the connection.
Scenario Outline has: (as python decorators can be stacked)
@pytest.mark.smoke
Scenario Outline: "VALID" Test
@pytest.mark.smoke
@pytest.mark.regression
Scenario Outline: "INVALID" Test
@pytest.mark.regression
Scenario Outline: "MIXED" Test
conftest.py
def pytest_bdd_apply_tag(tag, function):
if 'smoke' not in tag: #what should I use to take values from CLI and execute those
marker = pytest.mark.skip # skips scenario where 'smoke' is not marked
marker(function)
return True
return None
The above code in conftest.py skips all scenarios. CLI Input:
pytest --env='qa' -m 'smoke'
where pytest_addoption
is used for --env='qa'
and pytest_bdd_apply_tag
for -m
.
We want to execute only scenarios that have marked smoke(VALID & INVALID) when I pass smoke; scenarios that have marked regression(INVALID & MIXED) when I pass regression and default smoke when I don't pass any parameter in CLI via -m option.
My bad, I was wondering how I got mislead by the pytest markers with the scenario tag lines as mentioned in the documentation.
The changes I made on feature file is
@smoke
Scenario Outline: "VALID" Test
@smoke @regression
Scenario Outline: "INVALID" Test
@regression
Scenario Outline: "MIXED" Test
I've eliminated the pytest_bdd_apply_tag
method from conftest.py.
Giving this in the command line works for me
pytest -m "regression" --env="uat"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With