栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

conftest.py 配置测试脚本

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

conftest.py 配置测试脚本

import pytest
from py.xml import html


@pytest.fixture()
def before():
    print("------->fixture标记的函数before")


@pytest.fixture(autouse=True)  # 设置为自动运行
def before2():
    print("------->fixture自启动,默认作用域为 function")


@pytest.fixture(autouse=True, scope='class')
def before3():
    print("------->fixture自启动,作用域class")


@pytest.fixture()
def need_data():
    return 2  # 返回数字2


@pytest.fixture(params=[1, 2, 3])
def need_data2(request):  # 传入参数request 系统封装参数
    return request.param  # 取列表中单个值,默认的取值方式


# 修改报告样式
# 修改Environment
def pytest_configure(config):
    # 修改Platform
    config._metadata["Platform"] = "Windows 11"
    # 添加接口地址与项目名称
    config._metadata["项目名称"] = "pytest"
    #config._metadata['接口地址'] = 'xxxxxx'
    # 删除Java_Home
    # config._metadata.pop("JAVA_HOME")


# 修改Summary
@pytest.mark.optionalhook
def pytest_html_results_summary(prefix):
    prefix.extend([html.p("所属部门: 测试")])
    prefix.extend([html.p("测试人员: Mr.Liu")])


@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
    cells.pop(-1)  # 删除link标题


@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
    cells.pop(-1)  # 删除link列
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/935348.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号