如何在behave/python中传递参数

How to pass parameters in behave/python

我想知道如何传递 True 或 False 等参数。 (config_type = True) 在 python 语言中使用行为。

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)

这是在 BDD 中传递此类参数的正确方法吗?在下一次测试中,我想重用 someMethodconfig_type = False

我认为你很接近,但需要将 config_type 参数传递给 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)

就是说,您可能可以用这样的东西来整体清理它:

专题文件:

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    |

步骤文件:

@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)