在pytest html报告中,未正确显示ANSI颜色文本。但在控制台中,我可以看到没有任何issue.Please的输出请参阅我的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报告与所附图片的区别。[


发布于 2020-03-26 18:36:26
对我来说,在我按照https://github.com/pytest-dev/pytest-html#ansi-codes中的描述安装了所需的依赖项ansi2html之后(不使用Ansi2HTMLConverter),它就能正常工作。然而,我并没有实现pytest_runtest_makereport钩子。
https://stackoverflow.com/questions/58937666
复制相似问题