pytest-html生成报告中文乱码
版本信息:
pytest==7.2.2
先安装 pytest-html==3.2.0 卸载再安装pytest-html=3.1.1
conftest.py:
import pytest from py.xml import html tester = 'chai' def pytest_html_results_summary(prefix, summary, postfix): prefix.extend([html.p(f"测试人:@{tester}")]) def pytest_html_report_title(report): report.title = "冒烟测试" @pytest.mark.hookwrapper def pytest_runtest_makereport(item): outcome = yield report = outcome.get_result() if item.function.__doc__ is None: report.description = str(item.function.__name__) # 如果没有三引号注释('''注释'''),就提取函数名到case的输出文案中,就是上面的test_id else: report.description = str(item.function.__doc__) # 提取三引号注释('''注释''')到case的输出文案中 report.nodeid = report.nodeid.encode("unicode_escape").decode("utf-8") # 再把编码改回来