简体   繁体   English

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

[英]ANSI colour text not displayed in pytest-html report

In pytest html report, the ANSI colour text is not displayed correctly.在 pytest html 报告中,ANSI 彩色文本显示不正确。 But in console, I can see the output with out any issue.Please see my conftest.py and let me know if I have to make any changes to be displayed correctly.但是在控制台中,我可以看到 output 没有任何问题。请查看我的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)

please see the difference of Console out put and html report from the attached images.[请从附件中查看控制台输出和 html 报告的区别。 [控制台[1]

html报告

For me, it works right after I installed the required dependency ansi2html as described in https://github.com/pytest-dev/pytest-html#ansi-codes (without using the Ansi2HTMLConverter ).对我来说,它在我安装所需的依赖ansi2html后立即工作,如https://github.com/pytest-dev/pytest-html#ansi-codes中所述(不使用Ansi2HTMLConverter )。 However, I don't implement the pytest_runtest_makereport hook.但是,我没有实现pytest_runtest_makereport钩子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM