pytest html 增加列,如何添加额外的变量pytest html报告

您可以为每个测试插入自定义html,方法是将html内容添加到每个测试的“显示详细信息”部分,或者自定义结果表(例如添加一个票据列)。

第一种可能是最简单的,你可以添加以下到您的conftest.py

@pytest.mark.hookwrapper

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':

extra.append(pytest_html.extras.html('

some html

'))

report.extra = extra

在这里您可以与您的内容替换

some html

第二个解决办法是:

@pytest.mark.optionalhook

def pytest_html_results_table_header(cells):

cells.insert(1, html.th('Ticket'))

@pytest.mark.optionalhook

def pytest_html_results_table_row(report, cells):

cells.insert(1, html.td(report.ticket))

@pytest.mark.hookwrapper

def pytest_runtest_makereport(item, call):

outcome = yield

report = outcome.get_result()

report.ticket = some_function_that_gets_your_ticket_number()

记住,你可以随时与项目对象访问当前的测试,这可能帮助你获取需要的信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值