pytest断言
1. == 直接对两端的值进行判断是否一致 1==1
2.assert in 判断值是否在正确范围
def test_jia(self): a='hello' b='a' assert b in a
3.assert 判断值是否正确
def test_jia(self): a='hello' b='a' assert 1==1,'值不正确'
pytest 参数
普通运行用例时通过是无法打印出print的,这个时候需要添加参数打印出日志
-v
打印运行日志信息
-q
打印运行日志(简略)
-S
控制台输入结果
-k
运行包含关键字的用例
pytest -v-k'one' 运行用列名称包含one的用例
pytest -v-k' not one' 运行用列不名称包含one的用例
pytest mark标记
自定义标记
在要标记的方法前输入
@pytest.mark.jia
@pytest.mark.jia def test_jia(self): a='hello' b='e' assert b in a
在运行的时候,pytest -m'jia'
然而在使用自定义标签时,运行会有警告

这是因为我么你自定义的标记不被知道是用于什么,我们需要自己新建一个文件
pytest.ini
在项目下新建一个pytest.ini的配置文件,里面如下配置即可。markers=后面是标签名,如有多个,第二个开始要换行,且要缩进,不然还是会warning
[pytest] markers=jia
pytest用例执行后的几种状态
passed 用例通过
failed 用例不通过
error 用列编写问题
xfail --@pytest.mark.xfailed 预期失败
def test_xfailed(): pytest.xfail(reason='该功能正在开发') print('改功能正在调试')

skip 跳过用例不执行
@pytest.mark.skip(reason='此阶段不执行') def test_skip(self): print('此用例跳过')
skipif 有条件的跳过
a=0 @pytest.mark.skipif(a<1,reason='当前a小于1不执行用例') def test_skipif(self): print('满足条件不执行')

测试报告 pytest-html
安装插件
pip install pytest-html
执行命令
pytest --html=生成的路径

