Commits

jpellerin  committed 26fc5b4

Allow plugins loaded via entry points to override builtin plugins

  • Participants
  • Parent commits 474cbf3

Comments (0)

Files changed (2)

File nose/plugins/manager.py

         return iter(self.plugins)
 
     def addPlugin(self, plug):
+        # allow, for instance, plugins loaded via entry points to
+        # supplant builtin plugins.
+        new_name = getattr(plug, 'name', object())
+        self._plugins[:] = [p for p in self._plugins
+                            if getattr(p, 'name', None) != new_name]
         self._plugins.append(plug)
 
     def addPlugins(self, plugins):

File unit_tests/test_plugin_manager.py

     def loadTestsFromModule(self, module):
         raise AttributeError("I am missing my nose")
 
+class BetterPlug2(Plugin):
+    name = 'plug2'
+
 
 class TestPluginManager(unittest.TestCase):
 
         self.assertEqual(len(loaded), 2)
         for test in loaded:
             assert isinstance(test, nose.failure.Failure), \
-                   "%s is not a failure" % test
-        
+            "%s is not a failure" % test
+
+    def test_plugin_override(self):
+        pm = PluginManager(plugins=[Plug2(), BetterPlug2()])
+        self.assertEqual(len(pm.plugins), 1)
+        assert isinstance(pm.plugins[0], BetterPlug2)
 
 if __name__ == '__main__':
     unittest.main()