gpt4 book ai didi

python-3.x - pytest fixture 产量返回生成器而不是对象

转载 作者:行者123 更新时间:2023-12-04 14:21:04 25 4
gpt4 key购买 nike

我正在运行 pytest-3。我正在定义一个应该返回 falcon TestClient 对象的 fixture 。我也需要拆解,所以我试图让步。

def client():
api=create_app()
c = testing.TestClient(api)
yield c
remove_db()

如果我“返回”而不是“ yield ”,则测试用例运行得很好。
但是有了 yield,我的测试用例得到了一个生成器对象而不是一个 TestClient 对象

最佳答案

可能是因为该函数没有被标记为 fixture 。用 @pytest.fixture 装饰函数后尝试.例如,

@pytest.fixture(scope="session")
def client():
api=create_app()
c = testing.TestClient(api)
yield c
remove_db()

关于python-3.x - pytest fixture 产量返回生成器而不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54887336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com