当前位置: 首页>>代码示例>>Python>>正文


Python PluginManager.register方法代码示例

本文整理汇总了Python中_pytest.core.PluginManager.register方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.register方法的具体用法?Python PluginManager.register怎么用?Python PluginManager.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_pytest.core.PluginManager的用法示例。


在下文中一共展示了PluginManager.register方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_listattr_tryfirst

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [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]
开发者ID:ProProgrammer,项目名称:pytest,代码行数:32,代码来源:test_core.py

示例2: test_plugin_prevent_register

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_plugin_prevent_register(self):
     pluginmanager = PluginManager()
     pluginmanager.consider_preparse(["xyz", "-p", "no:abc"])
     l1 = pluginmanager.getplugins()
     pluginmanager.register(42, name="abc")
     l2 = pluginmanager.getplugins()
     assert len(l2) == len(l1)
开发者ID:ProProgrammer,项目名称:pytest,代码行数:9,代码来源:test_core.py

示例3: test_listattr

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_listattr(self):
     pluginmanager = PluginManager()
     class My2:
         x = 42
     pluginmanager.register(My2())
     assert not pluginmanager.listattr("hello")
     assert pluginmanager.listattr("x") == [42]
开发者ID:ProProgrammer,项目名称:pytest,代码行数:9,代码来源:test_core.py

示例4: test_plugin_prevent_register_unregistered_alredy_registered

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_plugin_prevent_register_unregistered_alredy_registered(self):
     pluginmanager = PluginManager()
     pluginmanager.register(42, name="abc")
     l1 = pluginmanager.getplugins()
     assert 42 in l1
     pluginmanager.consider_preparse(["xyz", "-p", "no:abc"])
     l2 = pluginmanager.getplugins()
     assert 42 not in l2
开发者ID:ProProgrammer,项目名称:pytest,代码行数:10,代码来源:test_core.py

示例5: test_notify_exception

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_notify_exception(self, capfd):
     pp = PluginManager()
     excinfo = pytest.raises(ValueError, "raise ValueError(1)")
     pp.notify_exception(excinfo)
     out, err = capfd.readouterr()
     assert "ValueError" in err
     class A:
         def pytest_internalerror(self, excrepr):
             return True
     pp.register(A())
     pp.notify_exception(excinfo)
     out, err = capfd.readouterr()
     assert not err
开发者ID:ProProgrammer,项目名称:pytest,代码行数:15,代码来源:test_core.py

示例6: test_register_imported_modules

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_register_imported_modules(self):
     pp = PluginManager()
     mod = py.std.types.ModuleType("x.y.pytest_hello")
     pp.register(mod)
     assert pp.isregistered(mod)
     l = pp.getplugins()
     assert mod in l
     pytest.raises(AssertionError, "pp.register(mod)")
     mod2 = py.std.types.ModuleType("pytest_hello")
     #pp.register(mod2) # double pm
     pytest.raises(AssertionError, "pp.register(mod)")
     #assert not pp.isregistered(mod2)
     assert pp.getplugins() == l
开发者ID:ProProgrammer,项目名称:pytest,代码行数:15,代码来源:test_core.py

示例7: test_firstresult_definition

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
    def test_firstresult_definition(self):
        pm = PluginManager()
        class Api:
            def hello(self, arg):
                "api hook 1"
            hello.firstresult = True

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")
        class Plugin:
            def hello(self, arg):
                return arg + 1
        pm.register(Plugin())
        res = mcm.hello(arg=3)
        assert res == 4
开发者ID:ProProgrammer,项目名称:pytest,代码行数:16,代码来源:test_core.py

示例8: test_happypath

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
    def test_happypath(self):
        pm = PluginManager()
        class Api:
            def hello(self, arg):
                "api hook 1"

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")
        assert hasattr(mcm, 'hello')
        assert repr(mcm.hello).find("hello") != -1
        class Plugin:
            def hello(self, arg):
                return arg + 1
        pm.register(Plugin())
        l = mcm.hello(arg=3)
        assert l == [4]
        assert not hasattr(mcm, 'world')
开发者ID:ProProgrammer,项目名称:pytest,代码行数:18,代码来源:test_core.py

示例9: test_register

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
    def test_register(self):
        pm = PluginManager(load=False)
        class MyPlugin:
            pass
        my = MyPlugin()
        pm.register(my)
        assert pm.getplugins()
        my2 = MyPlugin()
        pm.register(my2)
        assert pm.getplugins()[1:] == [my, my2]

        assert pm.isregistered(my)
        assert pm.isregistered(my2)
        pm.unregister(my)
        assert not pm.isregistered(my)
        assert pm.getplugins()[1:] == [my2]
开发者ID:ProProgrammer,项目名称:pytest,代码行数:18,代码来源:test_core.py

示例10: test_pm

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_pm(self):
     pp = PluginManager()
     class A: pass
     a1, a2 = A(), A()
     pp.register(a1)
     assert pp.isregistered(a1)
     pp.register(a2, "hello")
     assert pp.isregistered(a2)
     l = pp.getplugins()
     assert a1 in l
     assert a2 in l
     assert pp.getplugin('hello') == a2
     pp.unregister(a1)
     assert not pp.isregistered(a1)
     pp.unregister(name="hello")
     assert not pp.isregistered(a2)
开发者ID:ProProgrammer,项目名称:pytest,代码行数:18,代码来源:test_core.py

示例11: test_hook_tracing

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
    def test_hook_tracing(self):
        pm = PluginManager()
        saveindent = []
        class api1:
            x = 41
            def pytest_plugin_registered(self, plugin):
                saveindent.append(pm.trace.root.indent)
                raise ValueError(42)
        l = []
        pm.trace.root.setwriter(l.append)
        indent = pm.trace.root.indent
        p = api1()
        pm.register(p)

        assert pm.trace.root.indent == indent
        assert len(l) == 1
        assert 'pytest_plugin_registered' in l[0]
        pytest.raises(ValueError, lambda: pm.register(api1()))
        assert pm.trace.root.indent == indent
        assert saveindent[0] > indent
开发者ID:ProProgrammer,项目名称:pytest,代码行数:22,代码来源:test_core.py

示例12: test_pm_ordering

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_pm_ordering(self):
     pp = PluginManager()
     class A: pass
     a1, a2 = A(), A()
     pp.register(a1)
     pp.register(a2, "hello")
     l = pp.getplugins()
     assert l.index(a1) < l.index(a2)
     a3 = A()
     pp.register(a3, prepend=True)
     l = pp.getplugins()
     assert l.index(a3) == 0
开发者ID:ProProgrammer,项目名称:pytest,代码行数:14,代码来源:test_core.py

示例13: test_plugin_double_register

# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import register [as 别名]
 def test_plugin_double_register(self):
     pm = PluginManager()
     pm.register(42, name="abc")
     pytest.raises(ValueError, lambda: pm.register(42, name="abc"))
开发者ID:geraldoandradee,项目名称:pytest,代码行数:6,代码来源:test_core.py


注:本文中的_pytest.core.PluginManager.register方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。