【问题标题】:pytest fixture yield returns generator instead of objectpytest fixture yield 返回生成器而不是对象
【发布时间】:2019-07-20 02:30:21
【问题描述】:

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

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

如果我'return'而不​​是'yield',测试用例运行得很好。 但是通过 yield,我的测试用例得到了一个生成器对象而不是一个 TestClient 对象

【问题讨论】:

    标签: python-3.x pytest falconframework


    【解决方案1】:

    可能是因为该函数未标记为固定装置。用@pytest.fixture装饰函数后试试。例如,

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

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 2017-04-29
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多