Pytest-HTML 测试报告

一、官网资料

安装

$ pip install pytest-html

运行测试:

$ pytest --html=report.html

创建自包含报表:

为了遵守内容安全策略( CSP ) 插件,默认情况下,将分别存储CSS和图像等若干资产。 可以选择创建自包含报表,这在共享结果时更方便。 可以按以下方式执行这里操作:

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

作为文件或者链接添加的图像将被链接为外部资源,这意味着独立报表html文件可能不会像预期那样显示这些图像。

插件将在添加文件或者链接到独立报表时发出警告。

增强报告:

环境

web - config - 环境部分由pytest元数据插件提供,并可以通过 pytest_configure 钩子访问:

defpytest_configure(config):
config._metadata['foo'] ='bar'

额外内容

你可以在报表对象上创建'额外'列表,从而向HTML报告添加详细信息。 以下是可以添加的额外内容类型:

类型示例

 

 

原始 HTML

extra.html('<div>Additional HTML</div>')

JSON

extra.json({'name': 'pytest'})

纯文本

extra.text('Add some simple Text')

URL

extra.url('http://www.example.com/')

图像

extra.image(image, mime_type='image/gif', extension='gif')

图像

extra.image('/path/to/file.png')

图像

extra.image('http://some_image.png')

 

注释:当从文件中添加图像时,路径可以是绝对的,也可以是 relative。

注意 : 使用 --self-contained-html 时,添加为文件或者链接的图像可能无法按预期工作,有关更多信息,请参见创建自包含的报表。

对于几种图像格式也有方便的类型:

图像格式示例

PNG

extra.png(image)

JPEG

extra.jpg(image)

SVG

extra.svg(image)

 以下示例使用 pytest_runtest_makereport 钩子添加各种类型的附加项,可以在插件或者 conftest.py file: 中实现这些附加项

@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.url('http://www.baidu.com/'))
        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

你还可以为除 html 之外的所有类型指定 name 参数,这将更改创建的超级链接的标题:

extra.append(pytest_html.extras.text('some string', name='Different title'))

二、Allure Report本地打开报错

 1.无法本地打开,可以通过pycharm打开,pycharm自带容器服务,开启一个端口运行。

 2.Anywhere运行

        Anywhere是一个随启随用的静态服务器,它可以随时随地将你的当前目录变成一个静态文件服务器的根目录。

        安装之后,这个运行最简单,在report目录下打开cmd,输入anywhere就可以启动一个服务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值