繁体   English   中英

登录到 output 文件和行为标准输出

[英]Log into the output file AND stdout in behave

当我使用cmd 选项 -o将 output 重定向到 behave run 时,我看不到控制台中的回溯

使用 -o 的示例日志:

2021-05-24:14:42:52, INFO     | environment.py         :22   : Before all
2021-05-24:14:42:54, INFO     | launch_test.py         :144  : 1
2021-05-24:14:42:54, INFO     | launch_test.py         :147  : feature: autogen_Generate_Cloud.feature | name: Run all projects from specified folder -- @1.1 Projects | project: Test_Beamer_Car1 | number: 1 --> FAILED

未启用 -o 选项的日志示例:

Exception TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
2021-05-24:14:50:57, ERROR    | launch_test.py         :141  : Exception thrown during behave run
Traceback (most recent call last):
[REDACTED TRACEBACK]
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
2021-05-24:14:50:57, INFO     | launch_test.py         :144  : 1
2021-05-24:14:50:57, INFO     | launch_test.py         :147  : feature: autogen_Generate_Cloud.feature | name: Run all projects from specified folder -- @1.1 Projects | project: Test_Beamer_Car1 | number: 1 --> FAILED

我想要达到什么目的? 具有后一种日志格式,但 output 也重定向到文件。

我试过什么?:

我根据这个SO 帖子从 python 脚本运行行为(使用自定义运行器和上下文类)

我当前的行为参数:

[PATH to feature files],
"--no-summary",
"-k",
"--no-junit",
"-f=allure_behave.formatter:AllureFormatter",
"--no-capture",
"--no-capture-stderr",
f"-i={scenario.feature}",
f"--name={scenario.name}",
f"-o={output_file}"

我需要使用AllureFormatter ,因为该程序使用 allure 来生成报告,但它似乎捕获了控制台 output 并将其仅返回到文件,而不是 stdout 或 stderr

您可以组合多个格式和输出文件参数

所以通常要在 STDOUT 中看到 output 你会使用这个命令

behave --format pretty
behave --format json

如果你想发送 output 到一个文件你添加一个 output 参数

behave --format pretty --outfile behave.output

所以如果你只是组合它们,你会得到 output 到 STDOUT 和一个 output 文件

behave --format json --outfile behave.json --format pretty

为了安全起见,将 STDOUT --format 参数放在输出文件之后。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM