pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.32k stars 221 forks source link

pytest-bdd API only reads the latest "Background" key work #454

Closed arthuRHD closed 2 years ago

arthuRHD commented 3 years ago

No matter what filltering is applied, It's always the latest "Background" key work that gets collected. I would like to know how the pytest marks is used when collecting tests specified inside the feature file.

Concrete example :

Feature: My feature is awesome

    @foo 
    Background:
        Given The current value is 'foo'

    @bar
    Background:
        Given The current value is 'bar'

    @foo @bar
    Scenario: Generic test case scenario
        When doing something
        Then The value is validated

When i'm launching with pytest -m foo the value bar is selected

elchupanebrej commented 3 years ago

There is no possibility to use a few background sections with one scenario. If you really need this feature please address this question to Cucumber community. This project highly relies on decisions about Gherkin language developed there

olegpidsadnyi commented 2 years ago

Gherkin doesn't support multiple backgrounds on the feature level https://cucumber.io/docs/gherkin/reference/#background However it introduces new feature of Rules. Will have to have a look into that.