python - 访问 runtest 挂钩内的 pytest PluginManager 对象
问题描述
在 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.
...
解决方案
您始终可以通过会话对象访问配置:
def pytest_runtest_call(item):
manager = item.session.config.pluginmanager
推荐阅读
- for-loop - 如何移动使用循环功能制作的一些矩形
- c - 删除冗余参数导致分段错误,看似无缘无故
- c# - 寻找一个 VirtualKey 到真正的字符转换器功能
- javascript - 如何从 esModule 函数而不是平面函数中获取数据?
- python - Python 3 - 在列表中有 2 个项目作为 1 个索引
- authentication - ADFS 身份验证未传递到 _layouts 中的应用程序页面中的 Web 方法
- dialogflow-es - 对话流响应:在 google 上的操作
- parallel-processing - Beam/Dataflow - Big CoGroupByKey 结果导致流水线缓慢
- opendaylight - opendaylight 开发教程使用氟?
- angular - Angular2 - 样式绑定或属性中的百分比计算