Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 登录到输出文件,并在behave中进行标准输出_Python_Python 3.x_Python Behave - Fatal编程技术网

Python 登录到输出文件,并在behave中进行标准输出

Python 登录到输出文件,并在behave中进行标准输出,python,python-3.x,python-behave,Python,Python 3.x,Python Behave,当我将输出重定向到时,在运行期间,我无法在控制台中看到回溯 带有-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

当我将输出重定向到时,在运行期间,我无法在控制台中看到回溯

带有-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
我想要达到的目标是什么?具有后一种日志格式,但输出也重定向到文件

我试了什么

  • 在behave中关闭格式化程序和输出文件似乎可以完成这项工作
我根据SO post从python脚本运行behave(使用自定义运行程序和上下文类)

我当前的行为参数:

[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

最后解析输出文件,并在测试状态为“中断”时打印回溯。不是特别干净的溶液,但是,嘿,它很有效