1、pytest--参数化

  在测试用例的前面加上@pytest.mark.parametrize("参数名",列表数据)

 参数名:用来接收每一项数据,并作为测试用例的参数

 列表数据:一组测试数据

2、使用参数列表数据,iten表示的参数名,列表数据LD.error_data,item相当于LD.error_data中的每一条数据,在函数中传入item参数,按代码中的取值方式,获得列表数据中对应的数据

 1 from PageObjects.index_page import IndexPage
 2 from TestDatas import login_datas as LD
 3 import pytest
 4 from Common.tools.my_logger import MyLogger
 5 log=MyLogger()
 6 # 使用access_web,作用域是类级别,类上只执行一次
 7 @pytest.mark.usefixtures("access_web")
 8 #使用refresh_page,作用域是函数级别,作用在每一个函数上
 9 @pytest.mark.usefixtures("refresh_page")
10 @pytest.mark.one
11 class TestLogin:
12     # 异常用例--手机号码格式不正确(大于11位,小于11位,为空,不在号码段)
13     @pytest.mark.parametrize('item',LD.error_data)
14     def test_login_user_wrongFormat(self,item,access_web):
15         log.info("***********登录用例:异常场景:没有用户名/没有密码/用户名格式不对***********")
16         access_web[1].login(item['user'],item['pwd'])
17         assert access_web[1].get_errorMsg_form_loginArea()==item['check']
18     # 异常用例--手机号未注册,密码错误
19     @pytest.mark.parametrize('item',LD.noRegOrPwdError_data)
20     def test_login_noRegOrPwdError(self,item,access_web):
21         log.info("***********登录用例:异常场景:用户名未注册/密码错误***********")
22         access_web[1].login(item['user'],item['pwd'])
23         assert access_web[1].get_errorMsg_form_centerArea()==item['check']

pytest使用断言

assert 后面跟表达式(Ture or False)
posted on 2020-04-26 15:09  今天的事儿做完了吗  阅读(295)  评论(0编辑  收藏  举报