pytest 重试_pytest插件:pytest-html (执行用例失败后,自动截图到报告 + 失败用例重跑)...

本文介绍了如何使用pytest插件pytest-html和pytest-rerunfailures实现测试用例执行失败后的自动截图并嵌入报告,以及失败用例的重试功能。首先通过pip安装所需插件,然后在conftest.py文件中定义hookwrapper,当测试失败时捕获截图并保存至报告。此外,还提供了pytest命令行参数来设置重试次数和延迟时间。
摘要由CSDN通过智能技术生成

1、先pip安装插件: pytest-html、pytest-rerunfailures

2、用例执行失败自动截图到报告内 ,这个其实可以写到conftest.py文件。

当运行用例时遇到错误就会自己调用截图方法,并把截图存到html报告内

#固定脚本,可根据需要更改

from selenium import webdriver

import pytest

import os

driver = None

@pytest.mark.hookwrapper

def pytest_runtest_makereport(item):

"""

Extends the PyTest Plugin to take and embed screenshot in html report, whenever test fails.

:param item:

"""

pytest_html = item.config.pluginmanager.getplugin('html')

outcome = yield

report = outcome.get_result()

extra = getattr(report, 'extra', [])

if report.when == 'call' or report.when == "setup":

xfail = hasattr(report, 'wasxfail')

if (report.skipped and xfail) or (report.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值