3

我可以使用 --format 和 --outfile 参数运行我的行为代码,并按预期工作。

behave 00-test.feature --format json --outfile "C:/results.json"

这将为我提供 C:/results.json 中 json 格式的结果。

我想避免通过 behavior.ini 和命令行传递这些变量。我想在 enviroment.py 中设置这些变量,这样我就可以从任何地方简单地运行以下命令:

behave 00-test.feature

在 environment.py 文件中,我尝试了所有我能想到的组合,它们都归结为这三个变量,但没有运气。

def before_all(context):
    ...
    context.config.outfiles = ["C:/results.json"]
    context.config.outputs = [StreamOpener("C:/results.json")]
    context.config.formatters = ['json']
    ...

为什么选择 StreamOpener?https://github.com/behave/behave/blob/master/behave/configuration.py 显示输出是 StreamOpener 对象的列表。

有人知道在 python-behave 中设置输出文件和格式化程序的正确方法吗?

4

1 回答 1

1

这是一个解决方案吗?我从另一个这样的模块运行它

from behave import __main__ as behave_executable
behave_executable.main(args="--format json --outfile results.json")
于 2016-12-05T09:42:01.440 回答