pytest + pytest-html - Go语言中文社区

pytest + pytest-html


pytest --html=report.html --self-contained-html

1. 安装 pytest-html

运行: pytest scripts【your pytest scripts】 --html=report_default.html 【your html name and path】,报错,

pip3 install pytest-html 安装即可:

 

2 安装完后再次执行pytest脚本

pytest scripts --html=report_default.html

3 查看 生成的html

firefox report_default.html

4.发现用例名称没有显示,只显示了函数名称,增加一个 conftest.py 放在运行的目录下,conftest.py 放以下内容【让显示用例名称】,更多个性化编辑,如插入截图等请参考官网 https://pypi.org/project/pytest-html/

 

from datetime import datetime
from py.xml import html
import pytest
 
@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
    cells.insert(2, html.th('Description'))
    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.description))
    cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
    cells.pop()
 
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    # report.description = str(item.function.__doc__)
    report.description = str(item.function.__doc__)


# @pytest.hookimpl(hookwrapper=True)
# def pytest_runtest_makereport(item, call):
#     pytest_html = item.config.pluginmanager.getplugin('html')
#     outcome = yield
#     report = outcome.get_result()
#     extra = getattr(report, 'extra', [])
#     if report.when == 'call':
#         # always add url to report
#         extra.append(pytest_html.extras.text(item.function.text_plant))
#         # xfail = hasattr(report, 'wasxfail')
#         # if (report.skipped and xfail) or (report.failed and not xfail):
#         #     # only add additional html on failure
#         #     extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
#         report.extra = extra

 

5 这样就把用例的名字放了进来

6 注意 用例的名称就是 函数的说明信息

 

 

 

 

 

 

 

 

 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/Qton_CSDN/article/details/103182698
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-06-27 21:59:10
  • 阅读 ( 1226 )
  • 分类:前端

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢