當前位置: 首頁>>代碼示例>>Python>>正文


Python core.PluginManager類代碼示例

本文整理匯總了Python中_pytest.core.PluginManager的典型用法代碼示例。如果您正苦於以下問題:Python PluginManager類的具體用法?Python PluginManager怎麽用?Python PluginManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PluginManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_canonical_import

 def test_canonical_import(self, monkeypatch):
     mod = py.std.types.ModuleType("pytest_xyz")
     monkeypatch.setitem(py.std.sys.modules, 'pytest_xyz', mod)
     pp = PluginManager()
     pp.import_plugin('pytest_xyz')
     assert pp.getplugin('pytest_xyz') == mod
     assert pp.isregistered(mod)
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:7,代碼來源:test_core.py

示例2: test_listattr

 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,代碼行數:7,代碼來源:test_core.py

示例3: test_consider_module

 def test_consider_module(self, testdir):
     pluginmanager = PluginManager()
     testdir.syspathinsert()
     testdir.makepyfile(pytest_p1="#")
     testdir.makepyfile(pytest_p2="#")
     mod = py.std.types.ModuleType("temp")
     mod.pytest_plugins = ["pytest_p1", "pytest_p2"]
     pluginmanager.consider_module(mod)
     assert pluginmanager.getplugin("pytest_p1").__name__ == "pytest_p1"
     assert pluginmanager.getplugin("pytest_p2").__name__ == "pytest_p2"
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:10,代碼來源:test_core.py

示例4: test_import_plugin_dotted_name

    def test_import_plugin_dotted_name(self, testdir):
        pluginmanager = PluginManager()
        pytest.raises(ImportError, 'pluginmanager.import_plugin("qweqwex.y")')
        pytest.raises(ImportError, 'pluginmanager.import_plugin("pytest_qweqwex.y")')

        reset = testdir.syspathinsert()
        testdir.mkpydir("pkg").join("plug.py").write("x=3")
        pluginname = "pkg.plug"
        pluginmanager.import_plugin(pluginname)
        mod = pluginmanager.getplugin("pkg.plug")
        assert mod.x == 3
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:11,代碼來源:test_core.py

示例5: test_firstresult_definition

    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,代碼行數:14,代碼來源:test_core.py

示例6: test_pm_ordering

 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,代碼行數:12,代碼來源:test_core.py

示例7: test_happypath

    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,代碼行數:16,代碼來源:test_core.py

示例8: test_consider_module_import_module

    def test_consider_module_import_module(self, testdir):
        mod = py.std.types.ModuleType("x")
        mod.pytest_plugins = "pytest_a"
        aplugin = testdir.makepyfile(pytest_a="#")
        pluginmanager = PluginManager()
        reprec = testdir.getreportrecorder(pluginmanager)
        #syspath.prepend(aplugin.dirpath())
        py.std.sys.path.insert(0, str(aplugin.dirpath()))
        pluginmanager.consider_module(mod)
        call = reprec.getcall(pluginmanager.hook.pytest_plugin_registered.name)
        assert call.plugin.__name__ == "pytest_a"

        # check that it is not registered twice
        pluginmanager.consider_module(mod)
        l = reprec.getcalls("pytest_plugin_registered")
        assert len(l) == 1
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:16,代碼來源:test_core.py

示例9: test_consider_env_plugin_instantiation

 def test_consider_env_plugin_instantiation(self, testdir, monkeypatch):
     pluginmanager = PluginManager()
     testdir.syspathinsert()
     testdir.makepyfile(xy123="#")
     monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'xy123')
     l1 = len(pluginmanager.getplugins())
     pluginmanager.consider_env()
     l2 = len(pluginmanager.getplugins())
     assert l2 == l1 + 1
     assert pluginmanager.getplugin('xy123')
     pluginmanager.consider_env()
     l3 = len(pluginmanager.getplugins())
     assert l2 == l3
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:13,代碼來源:test_core.py

示例10: test_listattr_tryfirst

    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,代碼行數:30,代碼來源:test_core.py

示例11: test_plugin_prevent_register

 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,代碼行數:7,代碼來源:test_core.py

示例12: test_consider_setuptools_instantiation

    def test_consider_setuptools_instantiation(self, monkeypatch):
        pkg_resources = py.test.importorskip("pkg_resources")
        def my_iter(name):
            assert name == "pytest11"
            class EntryPoint:
                name = "pytest_mytestplugin"
                dist = None
                def load(self):
                    class PseudoPlugin:
                        x = 42
                    return PseudoPlugin()
            return iter([EntryPoint()])

        monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
        pluginmanager = PluginManager()
        pluginmanager.consider_setuptools_entrypoints()
        plugin = pluginmanager.getplugin("mytestplugin")
        assert plugin.x == 42
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:18,代碼來源:test_core.py

示例13: test_plugin_prevent_register_unregistered_alredy_registered

 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,代碼行數:8,代碼來源:test_core.py

示例14: test_hook_tracing

    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,代碼行數:20,代碼來源:test_core.py

示例15: test_import_plugin_importname

    def test_import_plugin_importname(self, testdir):
        pluginmanager = PluginManager()
        pytest.raises(ImportError, 'pluginmanager.import_plugin("qweqwex.y")')
        pytest.raises(ImportError, 'pluginmanager.import_plugin("pytest_qweqwx.y")')

        reset = testdir.syspathinsert()
        pluginname = "pytest_hello"
        testdir.makepyfile(**{pluginname: ""})
        pluginmanager.import_plugin("pytest_hello")
        len1 = len(pluginmanager.getplugins())
        pluginmanager.import_plugin("pytest_hello")
        len2 = len(pluginmanager.getplugins())
        assert len1 == len2
        plugin1 = pluginmanager.getplugin("pytest_hello")
        assert plugin1.__name__.endswith('pytest_hello')
        plugin2 = pluginmanager.getplugin("pytest_hello")
        assert plugin2 is plugin1
開發者ID:ProProgrammer,項目名稱:pytest,代碼行數:17,代碼來源:test_core.py


注:本文中的_pytest.core.PluginManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。