Pytest在运行时获取测试结果

时间:2018-10-23 22:59:41

标签: python pytest

有没有一种方法可以在运行时确定测试结果?本质上,我的程序当前所做的是不断记录测试,但是在运行每个测试之后,我也想将测试结果记录到相同的日志文件中。

我知道可用的插件可以在运行测试套件后生成测试报告,但这不是我想要的。

1 个答案:

答案 0 :(得分:-1)

您可以使用pytest的log-file开关。

pytest tests/ --log-file /tmp/pytest.log

您还可以自定义日志报告。来自pytest --help

logging: --no-print-logs disable printing caught logs on failed tests. --log-level=LOG_LEVEL logging level used by the logging module --log-format=LOG_FORMAT log format as used by the logging module. --log-date-format=LOG_DATE_FORMAT log date format as used by the logging module. --log-cli-level=LOG_CLI_LEVEL cli logging level. --log-cli-format=LOG_CLI_FORMAT log format as used by the logging module. --log-cli-date-format=LOG_CLI_DATE_FORMAT log date format as used by the logging module. --log-file=LOG_FILE path to a file when logging will be written to. --log-file-level=LOG_FILE_LEVEL log file logging level. --log-file-format=LOG_FILE_FORMAT log format as used by the logging module. --log-file-date-format=LOG_FILE_DATE_FORMAT log date format as used by the logging module.