[英]Access the pytest PluginManager object inside a runtest hook
In a pytest plugin, I want to access the configuration inside a runtest
hook.在 pytest 插件中,我想访问runtest
钩子内的配置。 This works, but feels like a hack.这有效,但感觉就像一个黑客。 Is there a cleaner way to do it?有没有更干净的方法来做到这一点?
configuration = None
def pytest_configure(config):
global configuration
configuration = config
def pytest_runtest_call(item):
manager = configuration.pluginmanager
# Do something with `manager` here.
...
You can always access the config via session object:您始终可以通过会话对象访问配置:
def pytest_runtest_call(item):
manager = item.session.config.pluginmanager
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.