3

在我的 pytest 脚本中,我需要自定义pytest-HTML报告以捕获标准输出,同时写入控制台,因为我在自动化测试中有用户输入。

test_TripTick.py

import os
import sys
import pytest

from Process import RunProcess
from recordtype import recordtype
from pip._vendor.distlib.compat import raw_input

@pytest.fixture(scope="module")
def Process(request):
    # print('\nProcess setup - module fixture')
    fileDirectory = os.path.abspath(os.path.dirname(__file__))
    configFilePath = os.path.join(fileDirectory, 'ATR220_Config.json')
    process = RunProcess.RunProcess()
    process.SetConfigVariables(configFilePath)
    process.GetComPort(["list=PID_0180"])

    def fin():
        sys.exit()
        request.addfinalizer(fin)

    return process


def test_WipeOutReader(Process):
    assert Process.WipeOutTheReader() == True


def test_LoadingKeysIntoMemoryMap(Process):
    assert Process.LoadingKeysIntoMemoryMap() == True


def test_LoadingFW(Process):  # only use bar
    assert Process.LoadingFW() == True


def test_LoadingSBL(Process):
    assert Process.LoadingSBL() == True


def test_CCIDReadForPaymentCards(Process):
    assert Process.CCIDReadWrite('Payment Card') == True

目前,如果我从 Windows 命令行运行以下命令,我会在控制台上获得输出,但在HTML report.

pytest C:\Projects\TripTickAT\test_TripTick.py -s --html=Report.html --verbose

另外,我想知道自定义HTML report可以更新file name,ordering test based on time of the executioncapturing the std-out.

4

1 回答 1

3

我已经尝试了 pytest 命令的附加标志。--capture sys-rP通过的测试。--capture sys对于失败的测试,-rF单击显示所有详细信息按钮后,我还可以在 html 文档中看到控制台日志,如输出所示。为了向您展示,我只捕获了部分屏幕。但是您可以向下滚动输出以查看所有控制台日志。下图中的灰色区域是控制台输出。无论测试失败或通过,我都不确定命令行级别标志是否有效。但这是一个临时解决方案。这将在命令行控制台和 html 日志控制台上打印日志

灰色区域是stid out`

于 2020-11-10T20:33:50.433 回答