コード例 #1
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
 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)
コード例 #2
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
 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)
コード例 #3
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
 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
コード例 #4
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
 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
コード例 #5
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
 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
コード例 #6
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
 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
コード例 #7
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
 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(ValueError, "pp.register(mod)")
     mod2 = py.std.types.ModuleType("pytest_hello")
     #pp.register(mod2) # double pm
     pytest.raises(ValueError, "pp.register(mod)")
     #assert not pp.isregistered(mod2)
     assert pp.getplugins() == l
コード例 #8
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
 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
コード例 #9
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
 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
コード例 #10
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    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
コード例 #11
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
    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]
コード例 #12
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
    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
コード例 #13
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    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]
コード例 #14
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    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
コード例 #15
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
 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)
コード例 #16
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    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)