pytest自动化测试框架

1.安装pytest

   pip install pytest  

2.报告插件allure

(1)下载allure,解压

(2)环境变量:path:bin目录

         

(3)安装pytest-allure插件

         pip install allure-pytest

3.pytest框架命名规范

 (1).py 测试文件必须以test_开头或者以_test结尾

 (2)测试类必须以Test开头,并且不能有init方法

 (3)测试方法必须以test_开头

 (4)断言必须使用assert

4.pytest数据驱动:参数化测试数据

   @pytest.mark.parametrize("x,y", test_Data)  (x,y)=[(x1,y1),(x2,y2).........]

import pytest

test_Data = [(1, 2), (3, 4), (5, 6)]


@pytest.mark.parametrize("x,y", test_Data)
def test_sum(x, y):
    print(x + y)

if __name__ == '__main__':
    pytest.main(["模块名", "-s"])

运行结果:

猜你喜欢

转载自blog.csdn.net/qq_19982677/article/details/107645807
今日推荐