pytest-dev / pytest-bdd

BDD library for the py.test runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.3k stars 219 forks source link

Tags support for Example sections #411

Open elchupanebrej opened 3 years ago

elchupanebrej commented 3 years ago

When I have Feature file like:

Feature: Foo
  Background:
    Given Step <bar>

    @cool_background_tag
    Examples:
    |bar|
    | 10|

    @nice_background_tag
    Examples:
    |bar|
    | 45|

  Scenario Outline: Fizz
    Given Step <buzz>

    @bad_scenario_tag
    Examples:
    |buzz|
    | 10|

    @ugly_scenario_tag
    Examples:
    |buzz|
    | 45|

and invoke pytest like:

# Runs Background only Examples for this tag:
pytest -m cool_background_tag
# Runs Scenario Outline only Examples for this tag:
pytest -m ugly_scenario_tag
# Other cases which also possible:
pytest -m "cool_background_tag and not bad_scenario_tag"
pytest -m "cool_background_tag or nice_background_tag"

pytest-bdd respects added tags

NB:

Gherkin parser already has such model and it already used here: https://behave.readthedocs.io/en/latest/new_and_noteworthy_v1.2.6.html#index-0

moattarwork commented 3 years ago

Any update on this feature?

willribemoreno commented 3 years ago

news?

elchupanebrej commented 3 years ago

@olegpidsadnyi could you please check #413 and provide some timeline for parser rewriting.

There could be one good step to untangle development: split parsing and execution models maybe with some marshalling in between as it was done in Cucmber.io project.

This feature uses aspects of Gherkin dialect which were not presented by Gherkin originally (pytest-bdd and Cucumber.io Gherkin dialects are different). I have a branch that could execute a model provided by Cucumber.io community. Before I could create new PR I want to know that this feature could have a future in this project.

@olegpidsadnyi please review this feature and put it if possible to a roadmap

VladimirChernev commented 1 year ago

bump

elchupanebrej commented 1 year ago

@VladimirChernev could I ask you to check https://github.com/elchupanebrej/pytest-bdd-ng fork? It doesn't support examples in background sections (because Gherkin specification doesn't support them), but it supports tags for example sections

AlirezaRoshanzamir commented 10 months ago

I implemented this feature using pytest-bdd internals and also using the pytest_collection_modifyitems function: https://stackoverflow.com/a/76653953/6628488