'''
pytest mark标记
1、跳过用例(有缺陷的用例跳过不执行)
2、选择部分用例执行,工程中用例规模越来越大,包含界面自动化、接口自动化、性能、冒烟测试
只想执行冒烟测试的用例,怎么办。
自定义标记。mark.后面的字符串自己定义的。
自定义标记在pytest.ini中注册下,执行时,加参数:
-M=“smoke" 执行带smoke标记的用例
-m=“func or smoke”执行带smoke标记或者带func标记的用例
-m=“func and smoke”执行带smoke标记且带func标记的用例
-m=“func and not smoke”执行带func标记,但是不带smoke标记的用例
'''
import pytest
version = 'V1R1'
@pytest.mark.smoke #冒烟用例
def test_001():
print("用例1")
@pytest.mark.skip("因为xxxx缺陷,该用例执行失败,待缺陷解决后再执行")
def test_002():
print("用例2")
#前面的表达式为true时跳过,为false时不跳过
@pytest.mark.skipif(version=='V1R1',reason="V1R2以上的版本增加的功能,V1R1尚不支持")
def test_003():
print("用例3")
@pytest.mark.func #功能用例
def test_004():
print("用例4")
@pytest.mark.func #给类加上标记,类中每个用例都带有这个标记
class Test001:
def test_005(self):
print("用例5")
@pytest.mark.smoke #冒烟用例
def test_006(self):
print("用例6")
def test_007(self):
print("用例7")
def test_008(self):
print("用例8")'''
用例有多个参数时,参数之间是全排列的。
一个字符串搜索的功能,有3个输入:
要搜索的字符串(大写、小写、混合)、
搜索方向(向上搜索、向下搜索)
是否区分大小写(区分、不区分)
'''
import pytest
@pytest.fixture(params=["Hello","HELLO","Hello"])
def searchStr(request):
return request.param
@pytest.fixture(params=["向上搜索","向下搜索"])
def fangXiang(request):
return request.param
@pytest.fixture(params=["区分","不区分"])
def daXiaoXin(request):
return request.param
#共执行3*2*2=12个用例
def test_search(searchStr,fangXiang,daoXiaoXin):
#字符串前面加f,{}中的内容打印时,用变量的值替换
print(f"测试搜索功能,要搜索的字符串为:{searchStr},搜索方向为:{fangXiang},是否区分大小写:{daoXiaoXin}")
'''
第三个版本:使用数据驱动的方式,实现注册接口的测试
'''
import pytest
import requests
@pytest.fixture(params=[("123","123456",'手机号格式不正确'),("13227907985","12345",'密码长度必须为6~18')])
def data(request):
return request.param
def test_register(data):
print("测试数据为:",data)
url = "http://192.168.2.36:8089/futureloan/mvc/api/member/register"
cs = {
"mobilephone": data[0],
"pwd": data[1]
}
r = requests.get(url,params=cs)
print(r.text)
assert r.json()['msg'] == data[2]
##########################################################################################
|