Commits

Anonymous committed 14f36fc

Added 2nd test layout to support dir, fixed testid bug so selected generator tests by id works, other small changes

Comments (0)

Files changed (14)

+\.noseids
 
 def main_():
     TestProgram.USAGE = USAGE_AS_MAIN
-    TestProgram(module=None, buffer=True, config=plugins.configFile())
+    TestProgram(module=None, config=plugins.configFile())
+
+

nose2/plugins/loader_compat.py

 
 from unittest2 import Plugin
 from unittest2.events import hooks
+from unittest2.util import getObjectFromName
 
 
 class LoaderCompat(Plugin):
     configSection = 'compat'
 
     def pluginsLoaded(self, event):
-        # ensure that my hook call comes first
+        # ensure that my hook calls come first
         hook = hooks.loadTestsFromModule
         hook -= self.loadTestsFromModule
         hook += self.loadTestsFromModule
 
+    #def loadTestsFromName(self, event):
+    #    parent, obj = getObjectFromName(event.name, event.module)
+    #    self._update(obj)
+
     def loadTestsFromModule(self, event):
         module = event.module
         # shim to make nose-style implicit generators
         # and test function fixtures 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
+            self._update(item)
+
+    def _update(self, obj):
+        if inspect.isfunction(obj):
+            if hasattr(obj, 'setup'):
+                obj.setUp = obj.setup
+            elif hasattr(obj, 'setUpFunc'):
+                obj.setUp = obj.setUpFunc
+            if hasattr(obj, 'teardown'):
+                obj.tearDown = obj.teardown
+            elif hasattr(obj, 'tearDownFunc'):
+                obj.tearDown = obj.tearDownFunc
+            if inspect.isgeneratorfunction(obj):
+                obj.testGenerator = True

nose2/plugins/plugins.cfg

 [generators]
 always-on = True
 
+[parameters]
+always-on = True
+
 [compat]
 always-on = True

nose2/plugins/testid.py

         return self.id
 
     def startTest(self, event):
-        testid = event.test.id()
+        testid = event.test.id().split('\n')[0]
         if testid not in self.tests:
             id_ = self.nextId()
             self.ids[id_] = testid

support/layout1/docs.rst

+>>> 1 == 1
+True

support/layout1/docs.txt

+>>> 2 == 2
+True
+>>> 3 == 2
+False

support/layout1/pkg1/__init__.py

+#

support/layout1/pkg1/mod1.py

+
+def some_other_func():
+    """This is a function with an inline doctest.
+
+    >>> a = 1
+    >>> b = 2
+    >>> a == b
+    False
+    """
+    pass

support/layout1/pkg1/test/__init__.py

+#

support/layout1/pkg1/test/test_things.py

+import unittest2
+
+class SomeTests(unittest2.TestCase):
+
+    def test_ok(self):
+        pass
+
+    def test_typeerr(self):
+        raise TypeError("oops")
+
+    def test_failed(self):
+        print "Hello stdout"
+        assert False, "I failed"
+
+    def test_skippy(self):
+        raise unittest2.SkipTest("I wanted to skip")
+
+
+def test_func():
+    assert 1 == 1
+
+
+def test_gen():
+    def check(a, b):
+        assert a == b
+    for i in range(0, 5):
+        yield check, (i, i,)
+test_gen.testGenerator = True
+
+did_setup = False
+def setup():
+    global did_setup
+    did_setup = True
+
+
+def test_fixt():
+    assert did_setup
+test_fixt.setup = setup
+

support/layout1/unittest.cfg

+[outcomes]
+treat-as-skip =
+    IOError
+    TodoError
+    TypeError
+treat-as-fail =
+    GlormpError

support/layout2/lib/pkg2/__init__.py

+def get_one():
+    return 1

support/layout2/tests.py

+from pkg2 import get_one
+
+def test():
+    assert get_one() == 1