Search code examples
python-behave

Python behave Gherkin Step parameter getting compile time Number expected exception


Feature: Step Parameter Test

  Scenario: look up a book
    Given I search for a valid book
    Then the result page will include "success"

  Scenario: look up an invalid book
    Given I search for a invalid book
    Then the result page will include "failure"

Step Definition: getting exception Number expected between {}, Not considering status as parameter

@then('the result page will include {status}')
def step_impl(context,status):
    """
    :type context: behave.runner.Context
    """
    pass

Exception Screenshot: enter image description here

I have tried even regular expression in that case getting steps undefined exception. didn't find any way to pass the string/number/double as parameter from feature file

Please do suggest if there is way to solve this.


Solution

  • It seems that, for whatever reason, your behave parser is 're'. when typically it's 'parse'. In your test file add the following:

    from behave import use_step_matcher
    
    use_step_matcher('parse')
    #the rest of your test here
    #@given...
    

    behave documentation on use_step_matcher here.