Pytset使用教程
目录
测试类
import pytest
class TestLogin1():
def test_case01(self,fixfup_function,fixfup_class):
print("test_csae01")
@pytest.mark.slow
def test_case02(self,fixfup_function,fixfup_class):
print("test_csae02")
def test_case03(self,fixfup_function,fixfup_class):
print("test_csae03")
@pytest.mark.gxj
def test_case04(self,fixfup_function,fixfup_class):
print("test_csae04")
class TestLogin2():
def test_case01(self,fixfup_function,fixfup_class):
print("test_csae01")
def test_case02(self,fixfup_function,fixfup_class):
print("test_csae02")
@pytest.mark.slow
def test_case03(self,fixfup_function,fixfup_class):
print("test_csae03")
def test_case04(self,fixfup_function,fixfup_class):
print("test_csae04")
@pytest.mark.skip
def test_case04(self,fixfup_function,fixfup_class):
print("test_csae04")
前置后置类方法/函数方法
contest.py
import pytest
@pytest.fixture()
def fixfup_function():
print("function前置")
yield
print("function后置")
#autouse=True
@pytest.fixture(scope="class",)
def fixfup_class():
print("class前置")
yield
print("class后置")
数据驱动-参数化
class Test_case01():
case = [
{"case_id":1,"data":"123","expectesd":"200","title":'登陆成功'},
{"case_id":2,"data": "123","expectesd":"200","title": '登陆失败'}
]
@pytest.mark.parametrize("item",case)
def test_dmeo01(self,item):
assert item["case_id"]==1000
用例标签
pytest.ini
[pytest]
markers =
slow
gxj
pytest收集用例执行
···
import pytest
pytest.main(["-s","-v"])
用例打标签运行
pytest.main(["-s","-v","-m","gxj or slow"])
生成pytset-html报告
pytest.main(["-s","-v","test_demo03.py","--html=reports/report.html"])
生成allure报告
1、下载allure报告https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
2、设置系统环境变量
3、执行生成报告文件:pytest.main(["-s","-v","test_demo03.py","--alluredir=reports/"])
4、allure runserve 报告路径
重运行机制 pip install pytest-rerunfailures
pytest.main(["-s","-v","test_demo03.py","--reruns","2","--reruns-delay","3","--alluredir=reports/"])
···
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)