ANSI彩色文本未显示在pytest-html报告中

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

在pytest html报告中,ANSI颜色文本显示不正确。但是在控制台中,我可以看到输出而没有任何问题。请查看我的conftest.py,让我知道是否需要进行任何更改才能正确显示。

from datetime import datetime
from py.xml import html
import pytest
import json
import globals
from Process.RunProcess import RunProcess
from os import path
import sys
from ansi2html import Ansi2HTMLConverter
from ansi2html.converter import main, \
    ANSI_VISIBILITY_ON, ANSI_VISIBILITY_OFF, \
    ANSI_BLINK_SLOW, ANSI_BLINK_FAST, ANSI_BLINK_OFF, \
    ANSI_NEGATIVE_ON, ANSI_NEGATIVE_OFF, \
    ANSI_INTENSITY_INCREASED, ANSI_INTENSITY_REDUCED, ANSI_INTENSITY_NORMAL
from ansi2html.util import read_to_unicode


@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
    # cells.insert(2, html.th('Status_code'))
    cells.insert(1, html.th('Time', class_='sortable time', col='time'))
    cells.pop()


@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
    # cells.insert(2, html.td(report.status_code))
    cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
    cells.pop()


@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    outcome = yield
    # Ansi2HTMLConverter(linkify=True).convert(outcome.get_result())
    report = outcome.get_result()
    # report.status_code = str(item.function)

请从附带的图像中查看控制台输出和html报告的差异。

HtmlReport

在pytest html报告中,ANSI颜色文本显示不正确。但是在控制台中,我可以看到输出没有任何问题。请查看我的conftest.py,让我知道是否需要进行任何更改...

python html pytest ansi-colors
1个回答
0
投票

对我来说,它在我按照ansi2html中的说明安装了必需的依赖项https://github.com/pytest-dev/pytest-html#ansi-codes之后就可以正常工作(不使用Ansi2HTMLConverter)。但是,我没有实现pytest_runtest_makereport挂钩。

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