本文整理汇总了Python中_pytest.core.PluginManager.getplugin方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.getplugin方法的具体用法?Python PluginManager.getplugin怎么用?Python PluginManager.getplugin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_pytest.core.PluginManager
的用法示例。
在下文中一共展示了PluginManager.getplugin方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_canonical_import
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [as 别名]
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)
示例2: test_import_plugin_importname
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [as 别名]
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
示例3: test_consider_module
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [as 别名]
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"
示例4: test_import_plugin_dotted_name
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [as 别名]
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
示例5: test_consider_env_plugin_instantiation
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [as 别名]
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
示例6: test_pm
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [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)
示例7: test_consider_setuptools_instantiation
# 需要导入模块: from _pytest.core import PluginManager [as 别名]
# 或者: from _pytest.core.PluginManager import getplugin [as 别名]
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