Behave, multiple steps with same name

Nikola Lošić

I have two feature files:

delete.feature
new_directory.feature

And two step files:

delete.py 
new_directory.py

Each one of the feature files begins like this:

Background:
  Given 'Workspace has the following structure'

Following the different tables.

When i write in step file decorator:

 @given('Workspace has the following structure') 

How does it know which feature file background belongs? When I run behave for

new_directory.feature

I can see that it runs that step from delete.feature. Is there any way to make difference between those files except from having all unique step names?

Louis

The way I've resolved having a shared step is to use a single implementation for the step that works differently depending on the feature that is using the step. Adapted to what you describe, it would be something like:

@given('Workspace has the following structure') 
def step_impl(context):
    feature = context.feature

    name = os.path.splitext(os.path.basename(feature.filename))[0]
    if name == "delete":
        # do something
        ...
    elif name == "new_directory":
        # do something else
        ...
    else:
        raise Exception("can't determine how to run this step")

The code above is based on checking the base name (minus extension) of the file that contains the feature. You could also check the actual feature name but I consider file names to be more stable than feature names so I prefer to test file names.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to create several implementation for the same named steps (behave)

From Dev

Comma seperated steps with one value to multiple steps with the same value

From Dev

Multiple parameters by the same name

From Dev

Multiple functions with the same name

From Dev

Multiple divs with same name

From Dev

Multiple inputs with same name

From Dev

How to deal with utilities with same name but behave differently between Unix variants?

From Dev

Why do multiple instances of a Python object behave as if they were the same?

From Dev

Do predicates concatenated in multiple brackets behave the same as the and operator?

From Dev

Multiple EJB beans with same name

From Dev

Multiple Inheritance: same variable name

From Dev

Multiple external packages with same name

From Dev

Multiple actions with same action name

From Dev

Laravel - multiple controllers with same name

From Dev

Saving multiple files with same name

From Dev

Submitting multiple inputs with same name

From Dev

Parse multiple headers with same name

From Dev

Multiple sling configs with same name

From Dev

Getting multiple subpatterns with the same name

From Dev

Multiple WiFi Networks with the Same Name

From Dev

post multiple fields with same name

From Dev

Saving multiple files with same name

From Dev

Multiple name servers on the same server

From Dev

multiple upload laravel with the same name

From Dev

Multiple controllers, same same controller name

From Dev

Multiple modals on with same element name on same page

From Dev

Behave: How to import steps from another file?

From Dev

Debugging python-behave steps with Pycharm

From Dev

How to skip steps in background of Behave BDD?

Related Related

HotTag

Archive