ranger
ranger

Reputation: 737

How to pass parameters in behave/python

I wonder how to pass True or False arguments such like. (config_type = True) using behave in python language.

Scenario Outline:
Given 
upload xls with parameters "shop" xlsx (path: "./upload12.xlsx") definition named "config_short" and  "<config_type>"

Examples:
      | config_type|
      | False    |

@given('upload xls with parameters "sh" xlsx (path: "./upload12.xlsx") definition named "config_short" and  "{config_type}"')
def step_impl(context, config_type)
definition = someMethod(xlsx_path, config_short, config_type=True)

Is that a proper way to pass such arguments in BDD? In next test I want to reuse that someMethod but with config_type = False

Upvotes: 2

Views: 4993

Answers (1)

Levi Noecker
Levi Noecker

Reputation: 3299

I think you are close, but need to pass the config_type parm through to someMethod:

Scenario Outline:
Given upload xls with parameters "shop" xlsx (path: "./upload12.xlsx") definition named "config_short" and  "<config_type>"

Examples:
      | config_type|
      | False    |

@given('upload xls with parameters "sh" xlsx (path: "./upload12.xlsx") definition named "config_short" and  "{config_type}"')
def step_impl(context, config_type):
    definition = someMethod(xlsx_path, config_short, config_type=config_type)

That said, you could probably clean that up overall with something like this:

Feature file:

Scenario Outline:
Given upload xls with parameters "<type>" xlsx (path: "<xls_path>") definition named "<config_name>" and  "<config_type>"

Examples:
      | type | xls_path        | config_name  | config_type|
      | shop | ./upload12.xlsx | config_short | False    |

step file:

@given('upload xls with parameters "{type}" xlsx (path: "{xls_path}") definition named "{config_name}" and  "{config_type}"')
def step_impl(context, type, xls_path, config_name, config_type):
    definition = someMethod(xlsx_path=xls_path, config_short=config_short, config_type=config_type)

Upvotes: 1

Related Questions