Anonymous avatar Anonymous committed db255d6

Added support for nose-style implicit test generators and some other test suite compatibility shims

Comments (0)

Files changed (3)

nose2/plugins/attrib.py

-from unittest2.events import hooks, Plugin, addOption
+from unittest2.events import Plugin, addOption
 from unittest import TestSuite
 
 undefined = object()

nose2/plugins/loader_compat.py

+import inspect
+
+from unittest2 import Plugin
+from unittest2.events import hooks
+
+
+class LoaderCompat(Plugin):
+    configSection = 'compat'
+
+    def pluginsLoaded(self, event):
+        # ensure that my hook call comes first
+        hook = hooks.loadTestsFromModule
+        hook -= self.loadTestsFromModule
+        hook += self.loadTestsFromModule
+
+    def loadTestsFromModule(self, event):
+        module = event.module
+        # shim to make nose-style implicit generators
+        # and test functions work with moduleloading plugin
+        for attr in dir(module):
+            item = getattr(module, attr, None)
+            if inspect.isfunction(item):
+                if hasattr(item, 'setup'):
+                    item.setUp = item.setup
+                elif hasattr(item, 'setUpFunc'):
+                    item.setUp = item.setUpFunc
+                if hasattr(item, 'teardown'):
+                    item.tearDown = item.teardown
+                elif hasattr(item, 'tearDownFunc'):
+                    item.tearDown = item.tearDownFunc
+                if inspect.isgeneratorfunction(item):
+                    item.testGenerator = True

nose2/plugins/plugins.cfg

         nose2.plugins.outcomes
         nose2.plugins.prof
         nose2.plugins.testid
+        nose2.plugins.loader_compat
+        unittest2.plugins.moduleloading
+
+[functions]
+always-on = True
+
+[generators]
+always-on = True
+
+[compat]
+always-on = True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.