web自动化:三.pytest 参数化

前言

环境:

centons 7.6
python 3.6
chrome 80.0.3987.132 
chromedriver 80.0.3987.16

selenium 3.14

自动化测试过程中,经常会出有些场景需要测试多种场景,例如:常见的登录页面需要对账号的类型,种类,长度等分别进行测试,引用pytest框架参数化能大大减少工作量,提升工作效力。

例1:

#coding:utf-8
import pytest
@pytest.mark.parametrize("test_input,excepted",[
("1+5",6),
("1+7",6),
("2+8",10),
])
def test_eval(test_input,excepted):
assert eval(test_input) == excepted

例2:

参数组合

import pytest
@pytest.mark.parametrize("x", [0, 1, 2])
@pytest.mark.parametrize("y", [3, 1, 2])
@pytest.mark.parametrize("z", [4, 5, 6])
def test_01(x,y,z):
print("x->%s,y->%s,z->%s" % (x, y,z))

 测试用例一共运行3*3*3=27条,参数组合的形式进行参数化测试。

例3:



原文地址:https://www.cnblogs.com/liushui0306/p/12513339.html