本文整理汇总了Python中_pytest.core.PluginManager.listattr方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.listattr方法的具体用法?Python PluginManager.listattr怎么用?Python PluginManager.listattr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_pytest.core.PluginManager
的用法示例。
在下文中一共展示了PluginManager.listattr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_listattr
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import listattr [as 别名]
def test_listattr(self):
pluginmanager = PluginManager()
class My2:
x = 42
pluginmanager.register(My2())
assert not pluginmanager.listattr("hello")
assert pluginmanager.listattr("x") == [42]
示例2: test_listattr_tryfirst
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import listattr [as 别名]
def test_listattr_tryfirst(self):
class P1:
@pytest.mark.tryfirst
def m(self):
return 17
class P2:
def m(self):
return 23
class P3:
def m(self):
return 19
pluginmanager = PluginManager()
p1 = P1()
p2 = P2()
p3 = P3()
pluginmanager.register(p1)
pluginmanager.register(p2)
pluginmanager.register(p3)
methods = pluginmanager.listattr('m')
assert methods == [p2.m, p3.m, p1.m]
# listattr keeps a cache and deleting
# a function attribute requires clearing it
pluginmanager._listattrcache.clear()
del P1.m.__dict__['tryfirst']
pytest.mark.trylast(getattr(P2.m, 'im_func', P2.m))
methods = pluginmanager.listattr('m')
assert methods == [p2.m, p1.m, p3.m]