pytest-html生成报告的时候Base URL去除方法

之前用pytest-html生成测试报告的时候,当pytest.main中--base_url不设置的时候,html的报告会带一个Base URL为空的行:

 

 

 

感觉不怎么好看,遂修改为:base_url 有值就展示,没有设置base_url就不展示这一行。

目前我想到的方法是修改源码:pytest-base-url中的plugin.py

1
2
3
4
5
6
7
8
def pytest_configure(config):
    if hasattr(config, "workerinput"):
        return  # don't run configure on xdist worker nodes
    base_url = config.getoption("base_url") or config.getini("base_url")
    if base_url is not None:
        config.option.base_url = base_url
        if hasattr(config, "_metadata"):
            config._metadata["Base URL"] = base_url

修改为(红色部分为修改内容,第6行,增加非空判断):

复制代码
1 目前我想到的方法是修改源码:pytest-base-url中的plugin.py
2 def pytest_configure(config):
3     if hasattr(config, "workerinput"):
4         return  # don't run configure on xdist worker nodes
5     base_url = config.getoption("base_url") or config.getini("base_url")
6     if base_url is not None and base_url != '':
7         config.option.base_url = base_url
8         if hasattr(config, "_metadata"):
9             config._metadata["Base URL"] = base_url
复制代码

 

  然后再跑pytest不设置base_url的时候,就不再展示Base URL这一行了

 

posted @   平行时空的旅者  阅读(223)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示