自动化测试-pytest

“”"
author:佳期如梦
function:pytest
date:2021-04-06
“”"
第一套方案
python + unittest + selenium + ddt/parameterized + HTMLTestRunner + yamgail
第二套方案
python + seldom(selenium + parameterized + HTMLTestRunner + pyyaml)
第三套方案
python + pytest + selenium + 自带的数据驱动 + pytest—html/allure + yamgail

pytest的优点:

1、写测试用例更简单
2、断言更简单一些 sef.assertEquesl(a,b) assert a != b
3、有非常强大的conftest.py的配置文件
4、自带数据驱动 (不好用)
5、allure 支持

pytest:

1、安装 pip install -U pytest
2、安装指定版本: pip install -U pytest==5.4.3
3、检查是否安装成功: pip show pytest
4、查看帮助信息: pytest -h

5、pytest是有规则的
*测试文件必须以test开头
*测试函数也必须以test开头
*测试类的命名必须以Test开头

pytest实例:

import pytest

def func(x):
return x + 1

#把测试相同的测试用例放到同一个类里面
class TestFunc:

def test_answer(self):
    assert func(3) == 5

def test_answer1(self):
    assert func(3) == 4

def test_answer2(self):
    assert func(-3) == -2

def add(a,b):
return a + b
class TestAdd:

def test_answer(self):
    assert add(3,1) == 5

def test_answer2(self):
    assert add(3, 1) == 5

def test_answer3(self):
    assert add(-3, 1) == 5

#运行
if name == ‘main’:
# pytest.main()
pytest.main(["-q",“test_sample02.py”])
print(“打印结果:”,pytest.main())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值