test_login(ddt)

import pytest
from login import login_check

datas = [
    {"user":'python37', "passwd": 'lemonban', "check": {"code": 0, "msg": "登录成功"} },
    {"user":'python37', "passwd": 'lemonban666', "check": {"code": 1, "msg": "账号或密码不正确"} },
    {"user": 'python370', "passwd": 'lemonban', "check": {"code": 1, "msg": "账号或密码不正确"}},
    {"user": None, "passwd": 'lemonban', "check": {"code": 1, "msg": "所有的参数不能为空"}},
    {"user": 'python37', "passwd": None, "check": {"code": 1, "msg": "所有的参数不能为空"}}
]




# @pytest.mark.usefixtures("class_fix")  # 调用函数名为class_fix的fixture.
@pytest.mark.usefixtures("hello2")   # 调用函数名为hello的fixture.
class TestLogin:

    @pytest.mark.parametrize("case",datas)
    def test_login(self,case):
        actual = login_check(case["user"], case["passwd"])
        assert actual == case["check"]

    # @pytest.fixture(scope="class", autouse=True)
    # def hello(self):
    #     # 前置准备工作的代码
    #     print("一条测试用例开始执行")
    #     print("6666666")
    #     yield
    #     # 后置清理工作的代码
    #     print("一条测试用例执行结束")


@pytest.mark.usefixtures("hello")
def test_hello_world():
    print("我是模块下的测试用例")

 

posted @ 2021-02-25 18:10  Memory荒年  阅读(99)  评论(0)    收藏  举报