如何将Pytest的日志附加到Allure Report中

问题描述 投票:1回答:1

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

请查看我所指的https://i.stack.imgur.com/1AePZ.png突出显示的代码

python-3.x pytest allure
1个回答
0
投票

stdout和stderr用于显示测试产生的输出到那些蒸汽。要在Allure报告中填充它们(和日志),测试执行的测试或应用程序必须生成相应流的输出。

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

上述测试结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.