Search code examples
pythonpython-behave

Skip a behave step in the step implementation


Is there a way to tell behave in a step implementation to skip the current step?

Something like:

@given("bla bla bla")
def step():
    skip_current_step()

The use case is that I want to check if some additional software is installed. If not, I want the complete scenario to be skipped.


Solution

  • I don't know if you can skip from inside of a step, but you can skip a whole scenario at feature level:

    def before_feature(context, feature):
        is_software_installed = some_foo_magic()
    
        if not is_software_installed:
            for scenario in feature.scenarios:
                if depends_on_software(scenario):
                    scenario.mark_skipped()
    

    Feature, Scenario, and ScenarioOutline all have a mark_skipped() method.