“”"
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())