pytest-dev / pytest-bdd

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

Execute pytest-bdd scenarios in specific order #437

Open idea1002 opened 3 years ago

idea1002 commented 3 years ago

Is there any way to execute pytest-bdd scenarios in specific order. I tried with tags @pytest.mark.order(1) @pytest.mark.order(2). It is not following the order specified.

elchupanebrej commented 3 years ago

Did you try https://pypi.org/project/pytest-order/ with "@scenario" decorator?

idea1002 commented 3 years ago

Did you try https://pypi.org/project/pytest-order/ with "@Scenario" decorator?

I tried to use the marker as @pytest.mark.order(order=1) on top of Scenario: name in feature file, something like

@pytest.mark.order(order=1) Scenario: This is first test

Is there another way ?

arthuRHD commented 3 years ago

When you implement scenarios in your python test file, did you apply this tag as a decorator on top of the test method ?

A workaround I can share for ordering with multiple feature files without pytest-order is to seperate the implementation in multiple python files by context. Then you import each files by your given order inside a test_entrypoint.py. Each test will be collected organically.

idea1002 commented 3 years ago

@arthuRHD I already have multiple feature files and step_definition files with separated scenarios. I applied the tag as decorator on scenario as I share the test methods with common steps I cannot use the tag on method directly.

Cito commented 1 year ago

Actually, the scenarios already run in a specific order by default, namely the order in which they are listed in the feature. And the features are ordered by feature name or feature file name if the features are not named.

So you can simply change the ordering of the scenarios in the feature files and the names of the features to enforce a certain order. I simply put a number in front of the feature names.

Btw, I think this behavior should be documented in the README file.