其他分享
首页 > 其他分享> > 【pytest】工厂化的fixtures

【pytest】工厂化的fixtures

作者:互联网

import pytest

@pytest.fixture()
def get_data():
    def fixtrue_factory(name):
        return {"name":name,"orders":[]}

    return fixtrue_factory

def test_demo(get_data):
    print(get_data("zhangsan"))
    print(get_data("lisi"))
    print(get_data("wangwu"))
import pytest

@pytest.fixture()
def get_data():
    data_mange = []

    def fixture_fac(name):
        data_mange.append(name)
        print("创建数据:",name)

    yield fixture_fac
    print(data_mange)

def test_demo1(get_data):
    print(get_data("zhangsan"))
    print(get_data("lisi"))
    print(get_data("wangwu"))

标签:name,get,fixture,工厂化,pytest,print,fixtures,data,def
来源: https://www.cnblogs.com/xwltest/p/16614471.html