如何将 Pytest 的日志附加到 Allure Report 中 [英] How to append logs of Pytest into Allure Report

查看:217
本文介绍了如何将 Pytest 的日志附加到 Allure Report 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 pytest 的所有日志显示到 Allure 中.stdout 和 stderr 用于什么?

How can i get to show all the logs of pytest into Allure. and what are stdout and stderr used for ?

请检查我所指的突出显示的代码

Please check the Highlighted Code which i am referring to

推荐答案

stdoutstderr 用于向这些流显示测试产生的输出.要将它们(和日志)填充到 Allure 报告中,您的测试或测试执行的应用程序必须向相应的流生成输出.

The stdout and stderr are used to display output produced by tests to those steams. To get them (and log) populated in Allure report your test or application executed by test have to produce output to corresponding streams.

import logging
import sys

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

def test_001():
    logger.info('Logged INFO message')
    logger.warning('Logged WARNING message')
    logger.error('Logged ERROR message')
    print('Message outputted to stdout')
    print('Message outputted to stderr', file=sys.stderr)
    assert 1 == 1

以上测试的输出:

这篇关于如何将 Pytest 的日志附加到 Allure Report 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆