python - 在 python behave 中设置输出和格式,特别是在 environment.py 中

标签 python python-behave

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

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

这将在 C:/results.json 中以 json 格式给我结果。

我想避免通过 behave.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 中设置输出文件和格式化程序的正确方法吗?

最佳答案

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

from behave import __main__ as behave_executable
behave_executable.main(args="--format json --outfile results.json")

关于python - 在 python behave 中设置输出和格式,特别是在 environment.py 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38515529/

相关文章:

python - 运行所有 Python bdd 行为和单元测试

python - 使用行为标签仅执行此类标签的子案例

python - 行为测试的模块化结构

python - 启动不同的驱动程序进行测试

Python Behave 在功能之间共享数据

python - 在 stdscr 中解释 "ENTER"按键(Python 中的 curses 模块)

python-docx 如何将不同的样式应用于表格中的不同单元格

python - Python中的静态类变量和方法

python - 将代码从当前文件复制到另一个Python文件

python - 如何检测用户是否在 Django REST(分页)的最后一页?