pytest:fixture中有入参时如何编写

如果fixture中需要入参时,不是直接返回数据,而是返回生成数据的函数。然后可以在测试用例中调用此函数。

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

    return _make_customer_record


def test_customer_records(make_customer_record):
    customer_1 = make_customer_record("Lisa")
    customer_2 = make_customer_record("Mike")
    customer_3 = make_customer_record("Meredith")

 

posted @ 2020-04-21 14:23  秋寻草  阅读(464)  评论(0编辑  收藏  举报