gpt4 book ai didi

python - 访问 runtest Hook 内的 pytest PluginManager 对象

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

在 pytest 插件中,我想访问 runtest Hook 内的配置。这可行,但感觉就像黑客。有更干净的方法吗?

configuration = None


def pytest_configure(config):
global configuration
configuration = config


def pytest_runtest_call(item):
manager = configuration.pluginmanager
# Do something with `manager` here.
...

最佳答案

您始终可以通过 session 对象访问配置:

def pytest_runtest_call(item):
manager = item.session.config.pluginmanager

关于python - 访问 runtest Hook 内的 pytest PluginManager 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54639242/

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