Python内置固定装置

卡拉


我正在尝试运行使用以下功能的pytest:

def storage_class(request):

    def fin():
        sc.delete()

    request.addfinalizer(fin)

    logger.info("Creating storage")
    data = {'api_version': 'v1', 'kind': 'namespace'}
    # data is ususally loaded from yaml template
    sc = OCS(**data)
    return sc

我在项目中找不到名为“ request”的灯具,因此我认为它是内置的灯具。但是,我在文档中进行了搜索,但是找不到“请求”内置装置:https : //docs.pytest.org/en/latest/builtin.html任何人都可以对此有所了解(内置?)夹具?谢谢!

山姆·丹尼尔

request 固定装置有助于获取有关上下文的信息。

可根据要求提供更多夹具

请求固定示例

请求夹具最常见的用法是addfinalizerconfig

而且,如果您只需要teardown功能,则可以简单地使用ayield并摆脱request固定装置。

@pytest.fixture()
def storage_class():

    logger.info("Creating storage")
    data = {'api_version': 'v1', 'kind': 'namespace'}
    sc = OCS(**data)
    yield sc

    # Any code after yield will give you teardown effect
    sc.delete()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章