简体   繁体   English

在 runtest 挂钩中访问 pytest PluginManager 对象

[英]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.

相关问题 在 pytest_runtest_logreport 中访问 pytest 会话或参数 - Access pytest session or arguments in pytest_runtest_logreport 如何将夹具对象传递给 pytest_runtest_makereport? - How to pass fixture object to pytest_runtest_makereport? 如何通过检查传递给pytest_runtest_teardown的Item对象来确定测试是通过还是失败? - How can I determine if a test passed or failed by examining the Item object passed to the pytest_runtest_teardown? pytest框架的通用运行测试钩子示例 - Example of generic runtest hooks for pytest framework 是否调用 pytest_runtest_teardown 来跳过测试,而 pytest_runtest_setup 不是? - Is pytest_runtest_teardown called for skipped tests while pytest_runtest_setup is not? Pytest插件:重写pytest_runtest_call和朋友 - Pytest plugin: Overriding pytest_runtest_call and friends AttributeError:对象没有属性'runTest' - AttributeError: object has no attribute 'runTest' AttributeError: 'module' 对象没有属性 'runTest' - AttributeError: 'module' object has no attribute 'runTest' 是否可以在pytest_runtest_call pytest函数中向测试函数添加更多参数? - Is it possible to add one more parameter to test function in pytest_runtest_call pytest function? Python unittest.TestCase 对象没有属性“runTest” - Python unittest.TestCase object has no attribute 'runTest'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM