web自动化6-pytest⑦一些基本情况

命名规则

1)import pytest

测试文件名要以test_ 开头或 _test结尾

2)类名需要以Test开头(T),不能带有init方法

3)函数名以test_开头(t)

符合规则框架才能找到用例,一条用例代表一条函数
2.

pip install pytest

优点:在内存中回收用例内容

提高运行效率,不用再次调用方法

运行方式,pytest.main(\[\])

pytest.main("-s") 里面可以输入内容,list列表

pytest.main("-s","-m run") -m remark的意思,运行run标签的用例
4.

跳过用例,

在方法上面加@pytest.mark.skip

运行 pytest.main(\[\])
5.

@pytest.mark.run

@pytest.mark.modelName

pytest.main("-s","-m modelName")
6.

报告生成:pip install pytest-html,使用allure会更好些,也更简单

生成自带的,modeName的用例报告

pytest.main("-s","-m modeName","--html=report.html")
7.

关键函数,setup(),预置条件

重置环境,teardown()

pytest.mark.baidu

def setup_class(self) #类预置条件 ,需要将用例用类进行包裹

def teardown_class(self) #类重置环境 ,需要将用例用类进行包裹

setup和teardown操作

setup在测试函数或类之前执行,完成准备工作,例如:数据库连接、测试数据、打开文件等

teardown,在测试函数或类之后执行,完成收尾工作,例如:断开数据库、回收内存资源等
9.

传参

@pytest.mark.parametrize('username,password'),('your','123456','用户名不正确'),('you','123456','ok')

思路:

断言,assert

封装

数据与业务抽离,优化

数据写另外文件

python 复制代码
if __name__ == '__main__':
	pytest.main(['-sv','test_py.py'])
相关推荐
天远API32 分钟前
零信任架构实战:基于天远全能消金报告构建自动化消费分期网关
运维·人工智能·架构·自动化
黄昏恋慕黎明1 小时前
博客论坛技术迭代
python·pytest
代码方舟2 小时前
零信任架构实战:基于天远全能消金报告构建自动化信用合规网关
运维·人工智能·架构·自动化
Bruce_Liuxiaowei2 小时前
录屏片段无损合并:从 ffmpeg concat 原理到 Python 自动化脚本
python·ffmpeg·自动化
2601_962078233 小时前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
AlanBruce3 小时前
摩尔信使MThings CJ/T 188数据配置使用指南
自动化·modbus·摩尔信使
杨女士YRJ4 小时前
python+pytest+01
python·pytest
长谷深风1114 小时前
AI自动化中的关键闸门:何时必须人工审批?
大数据·人工智能·ai·自动化·ai agent·智能体·hitl
海宇数据5 小时前
零信任架构实战:基于海宇对外投资历史查询服务构建自动化异动企业筛查网关
运维·人工智能·架构·自动化
迷途呀16 小时前
CI/CD 自动化部署实践:让代码提交后自动上线
linux·运维·nginx·ci/cd·自动化