python - 登录到输出文件和标准输出的行为
问题描述
当我使用cmd 选项 -o将输出重定向到时,我在行为运行期间看不到控制台中的回溯
带有 -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
我想要达到什么目的?具有后一种日志格式,但输出也重定向到文件。
我试过什么?:
我根据this SO post从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 生成报告,但它似乎捕获控制台输出并将其仅返回到文件,而不是 stdout 或 stderr
解决方案
您可以组合多个格式和输出文件参数
所以通常要在 STDOUT 中看到输出,你会使用这个命令
behave --format pretty
behave --format json
如果要将输出发送到文件,请添加输出参数
behave --format pretty --outfile behave.output
所以如果你只是将它们组合起来,你会得到输出到 STDOUT 和一个输出文件
behave --format json --outfile behave.json --format pretty
为了安全起见,将您的 STDOUT --format 参数放在 outfile 之后。
推荐阅读
- react-native - 在 TabNavigator 中重置当前 Stack 并导航到其他 Stack (react-navigation)
- java - 如何在 JUnit 测试期间消除“缺少 Hibernate 审计表”WARN 消息
- c - 为什么从 sockaddr_in 到 sockaddr 的转换有效
- javascript - javascript Promise 中的异步操作最终阻塞
- shell - 需要在TCL脚本中结合linux命令
- java - Java - 取消期货
- xamarin.forms - Xamarin.Forms DatePicker.SetValue(BindableProperty,值)
- python - Python 多处理使用比指定更多的 CPU
- angular - Angular 从 API 检索数据
- java - 我的 Android Button 需要点按两次才能工作