python接口自动化-mark分级(4)

分级运行:我们有的时候,在运行测试用例的过程中,想要运行部分测试用例,可以用 mark进行分级
工作中的使用场景:冒烟测试,分模块执行测试用例。
比如:现在自动化代码运行过程中,1000条测试用例,有200条报错,我们需要先跑主干流程,也就是核心测试用例。
import pytest, requests


class TestLogin:
    # 1.正确流程
    @pytest.mark.T1
    def test_login01(self):
        response = requests.post(url='http://127.0.0.1:5000/user_login',
                                 data={"username": "xiaohua", "password": "a123456"})
        res = response.json()
        print(res)
        assert {'code': '1000', 'msg': '登录成功'} == res

    # 2.用户名错误
    @pytest.mark.T2
    def test_login02(self):
        response = requests.post(url='http://127.0.0.1:5000/user_login',
                                 data={"username": "xiaoniu1", "password": "a123456"})
        res = response.json()
        print(res)
        assert "用户名或密码错误" in str(res)

    # 3.用户名为空
    @pytest.mark.T2
    def test_login03(self):
        response = requests.post(url='http://127.0.0.1:5000/user_login',
                                 data={"username": "", "password": "a123456"})
        res = response.json()
        print(res)
        assert res["msg"] == "用户名不能为空!" and res["code"] == "1003"  # 断言响应结果中的value值是否和预期结果一致

    # 4.密码错误
    @pytest.mark.T2
    def test_login04(self):
        response = requests.post(url='http://127.0.0.1:5000/user_login',
                                 data={"username": "xiaoniu", "password": "a1234567"})
        res = response.json()
        print(res)
        assert {'code': '1005', 'msg': '用户名或密码错误!'} == res

    # 5.密码为空
    @pytest.mark.T1
    def test_login05(self):
        response = requests.post(url='http://127.0.0.1:5000/user_login',
                                 data={"username": "xiaoniu", "password": ""})
        res = response.json()
        print(res)
        assert {'code': '1004', 'msg': '密码不能为空!'} == res


if __name__ == "__main__":
    # 知识点1: 运行该模块下的所有测试用例  -s -v -q
    # pytest.main(['-vs','./test_pytest03_1.py'])  # 运行指定模块
    pytest.main(['-vs','-m T1', './test_pytest03_1.py'])  # 运行指定模块

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值