Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Behave - Two different steps with the same name

I'm running my python tests with Behave

What i want to do is implement the same step, e.g "UserA calls UserB" in diffrent step files and to point the test to the correct step teach time.

For example:

The .feature file content:

Scenario: User A calls User B
  Given UserA calls UserB

then, in the step folder, i'll have a .py file that will contain:

@given('UserA calls UserB')
def step_impl(context):
   print('A call is being made')

And another step .py file that will contain:

@given('UserA calls UserB')
def step_impl(context):
   print('A call is being made in another method')

I want to have control over which one of these steps will be executed. Is there a clean way to do that?

like image 962
Shizzle Avatar asked Sep 14 '25 07:09

Shizzle


1 Answers

Found the answer after asking in the behave Github repository:

The best way to differentiate steps is to use test stages.

Example:

If i want to write the same steps with different implementation using the same .feature file i can open two directories:

dev_steps/
integration_steps/

and point to each of them in the behave command using stage:

behave --stage=dev

or

behave --stage=integration
like image 129
Shizzle Avatar answered Sep 17 '25 21:09

Shizzle