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列