【问题标题】:ANSI colour text not displayed in pytest-html reportpytest-html 报告中未显示 ANSI 彩色文本
【发布时间】:2020-03-15 04:28:24
【问题描述】:

在 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报告的区别。[

【问题讨论】:

  • 有人能回答我的问题吗,我非常期待得到答案。

标签: python html pytest ansi-colors


【解决方案1】:

对我来说,它在我安装了所需的依赖项 ansi2html 后立即工作,如 https://github.com/pytest-dev/pytest-html#ansi-codes 中所述 (不使用Ansi2HTMLConverter)。但是,我没有实现 pytest_runtest_makereport 钩子。

【讨论】:

    猜你喜欢
    • 2016-02-25
    • 2022-10-08
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 2017-04-19
    相关资源
    最近更新 更多