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