Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute pytest-bdd scenarios in specific order #437

Open
idea1002 opened this issue Aug 3, 2021 · 5 comments
Open

Execute pytest-bdd scenarios in specific order #437

idea1002 opened this issue Aug 3, 2021 · 5 comments

Comments

@idea1002
Copy link

idea1002 commented Aug 3, 2021

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
Copy link

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

@idea1002
Copy link
Author

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
Copy link

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
Copy link
Author

idea1002 commented Nov 3, 2021

@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
Copy link
Member

Cito commented Jul 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants