【问题标题】:How to capture the log details on pytest-html as well as writing in to Console?如何捕获 pytest-html 上的日志详细信息以及写入控制台?
【发布时间】:2019-11-08 15:42:46
【问题描述】:

在我的 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 nameordering test based on time of the executioncapturing the std-out

【问题讨论】:

    标签: console capture pytest-html


    【解决方案1】:

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

    `

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 2018-10-06
      • 1970-01-01
      相关资源
      最近更新 更多