[py-svn] commit/pytest: hpk42: change pluginmanager.register API to raise ValueError if the plugin object or the name is already registered

Bitbucket commits-noreply at bitbucket.org
Sat Jun 16 21:47:45 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/19b833627c88/
changeset:   19b833627c88
user:        hpk42
date:        2012-06-16 21:29:04
summary:     change pluginmanager.register API to raise ValueError if the plugin object or the name is already registered
affected #:  5 files

diff -r 6821b39204a30739807058e209efc566274b91be -r 19b833627c882e7c0db2b566da7c31ea3c68b57c CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@
 -----------------------------------
 
 - fix issue128: show captured output when capsys/capfd are used
+- pluginmanager.register(...) now raises ValueError if the
+  plugin has been already registered or the name is taken
 
 Changes between 2.2.3 and 2.2.4
 -----------------------------------


diff -r 6821b39204a30739807058e209efc566274b91be -r 19b833627c882e7c0db2b566da7c31ea3c68b57c _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.2.5.dev1'
+__version__ = '2.2.5.dev2'


diff -r 6821b39204a30739807058e209efc566274b91be -r 19b833627c882e7c0db2b566da7c31ea3c68b57c _pytest/core.py
--- a/_pytest/core.py
+++ b/_pytest/core.py
@@ -79,10 +79,11 @@
                 self.import_plugin(spec)
 
     def register(self, plugin, name=None, prepend=False):
-        assert not self.isregistered(plugin), plugin
+        if self._name2plugin.get(name, None) == -1:
+            return
         name = name or getattr(plugin, '__name__', str(id(plugin)))
-        if name in self._name2plugin:
-            return False
+        if self.isregistered(plugin, name):
+            raise ValueError("Plugin already registered: %s=%s" %(name, plugin))
         #self.trace("registering", name, plugin)
         self._name2plugin[name] = plugin
         self.call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self})


diff -r 6821b39204a30739807058e209efc566274b91be -r 19b833627c882e7c0db2b566da7c31ea3c68b57c setup.py
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@
         name='pytest',
         description='py.test: simple powerful testing with Python',
         long_description = long_description,
-        version='2.2.5.dev1',
+        version='2.2.5.dev2',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 6821b39204a30739807058e209efc566274b91be -r 19b833627c882e7c0db2b566da7c31ea3c68b57c testing/test_core.py
--- a/testing/test_core.py
+++ b/testing/test_core.py
@@ -32,6 +32,11 @@
         l2 = pluginmanager.getplugins()
         assert 42 not in l2
 
+    def test_plugin_double_register(self):
+        pm = PluginManager()
+        pm.register(42, name="abc")
+        pytest.raises(ValueError, lambda: pm.register(42, name="abc"))
+
     def test_plugin_skip(self, testdir, monkeypatch):
         p = testdir.makepyfile(skipping1="""
             import pytest
@@ -203,10 +208,10 @@
         assert pp.isregistered(mod)
         l = pp.getplugins()
         assert mod in l
-        pytest.raises(AssertionError, "pp.register(mod)")
+        pytest.raises(ValueError, "pp.register(mod)")
         mod2 = py.std.types.ModuleType("pytest_hello")
         #pp.register(mod2) # double pm
-        pytest.raises(AssertionError, "pp.register(mod)")
+        pytest.raises(ValueError, "pp.register(mod)")
         #assert not pp.isregistered(mod2)
         assert pp.getplugins() == l

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list