• pytest(二十一)--使用多个fixture和fixture直接互相调用


    使用多个fixture

    如果用例需要用到多个fixture的返回数据,fixture也可以return一个元组、list或字典,然后从里面取出对应数据。

    #test_fix1.py
    import pytest
    @pytest.fixture()
    def user():
        a="admin"
        b="123456"
        return (a,b)
    def test_t1(user):
        u=user[0]
        p=user[1]
        print("user类型{}".format(type(user))) #查看返回类型
        print("用户名:{},密码:{}".format(u,p))
        assert u=="admin"
    if __name__=="__main__":
        pytest.main(["test_fix1.py"])
    

     运行结果:

    当然也可以分开定义成多个fixture,然后test_用例传多个fixture参数

    #test_fix1.py
    import pytest
    @pytest.fixture()
    def user():
        a="admin"
        return a
    
    @pytest.fixture()
    def pwd():
        p="888888"
        #return p
    def test_t1(user,pwd):
        u=user
        p=pwd
        print("user类型{}".format(type(user))) #查看返回类型
        print("用户名:{},密码:{}".format(u,p))
        assert p==None
    if __name__=="__main__":
        pytest.main(["test_fix1.py"])  

    运行结果

     fixture与fixture互相调用

    #test_fix1.py
    import pytest
    @pytest.fixture()
    def user():
        a="admin"
        return a
    
    @pytest.fixture()
    def pwd(user):
        p="888888"
        return user,p
    def test_t1(user,pwd):
        u=user
        p=pwd[1]
        print("pwd类型{}".format(type(pwd))) #查看返回类型
        print("用户名:{},密码:{}".format(u,p))
        assert p!=None
    if __name__=="__main__":
        pytest.main(["test_fix1.py"]) 

    运行结果:

      

    越努力,越幸运!!! good good study,day day up!!!
  • 相关阅读:
    mui 卡片视图 遮罩蒙版
    mui 滑块开关 进度条 以及如何获取值
    mui 普通新闻文字列表 图文新闻列表
    HDU4553 约会安排
    HDU4614 Vases and Flowers
    HDU 1540 Tunnel Warfare 线段树区间合并
    Codeforces Round #359 (Div. 1)
    POJ3264 Balanced Lineup 线段树区间最大值 最小值
    1351 topcoder 吃点心
    POJ 3321 Apple Tree(dfs序树状数组)
  • 原文地址:https://www.cnblogs.com/canglongdao/p/13408273.html
Copyright © 2020-2023  润新知