在pytest插件中,我想访问runtest
挂钩内的配置。这行得通,但感觉像是黑客。有更清洁的方法吗?
configuration = None
def pytest_configure(config):
global configuration
configuration = config
def pytest_runtest_call(item):
manager = configuration.pluginmanager
# Do something with `manager` here.
...
答案 0 :(得分:1)
您始终可以通过会话对象访问配置:
def pytest_runtest_call(item):
manager = item.session.config.pluginmanager