Repository: nose-devs/nose2

Issue:
Improve mp plugin's command line help
'# o procs' does not quite cut it, IMHO.

Comments:

Patch:
diff --git a/nose2/plugins/loader/functions.py b/nose2/plugins/loader/functions.py
index d7b6563..5bd7212 100644
--- a/nose2/plugins/loader/functions.py
+++ b/nose2/plugins/loader/functions.py
@@ -87,6 +87,7 @@ class Functions(Plugin):
 
         parent, obj, name, index = result
         if (isinstance(obj, types.FunctionType) and not
+            isinstance(parent, type) and not
             util.isgenerator(obj) and not
             hasattr(obj, 'paramList') and
             util.num_expected_args(obj) == 0):
diff --git a/nose2/plugins/mp.py b/nose2/plugins/mp.py
index 33f488e..da71f7e 100644
--- a/nose2/plugins/mp.py
+++ b/nose2/plugins/mp.py
@@ -22,7 +22,7 @@ class MultiProcess(events.Plugin):
     configSection = 'multiprocess'
 
     def __init__(self):
-        self.addArgument(self.setProcs, 'N', 'processes', '# o procs')
+        self.addArgument(self.setProcs, 'N', 'processes', 'Number of processes used to run tests (0 = auto)')
         self.testRunTimeout = self.config.as_float('test-run-timeout', 60.0)
         self._procs = self.config.as_int(
             'processes', 0)
@@ -46,7 +46,7 @@ class MultiProcess(events.Plugin):
     def procs(self, value):
         """Setter for procs property"""
         if value < 0:
-            raise AttributeError("Can't set the procs number to less than 0, (0 = Auto)")
+            raise ValueError("Number of processes cannot be less than 0")
         self._procs = value
 
     def setProcs(self, num):


Test patch:
diff --git a/nose2/tests/unit/test_functions_loader.py b/nose2/tests/unit/test_functions_loader.py
index cf1d6fd..e6fd25d 100644
--- a/nose2/tests/unit/test_functions_loader.py
+++ b/nose2/tests/unit/test_functions_loader.py
@@ -1,4 +1,11 @@
 import unittest
+
+try:
+    from unittest import mock
+except ImportError:
+    # Python versions older than 3.3 don't have mock by default
+    import mock
+
 from nose2 import events, loader, session
 from nose2.plugins.loader import functions
 from nose2.tests._common import TestCase
@@ -47,3 +54,37 @@ class TestFunctionLoader(TestCase):
         event = events.LoadFromModuleEvent(self.loader, m)
         self.session.hooks.loadTestsFromModule(event)
         self.assertEqual(len(event.extraTests), 0)
+
+    def test_can_load_test_functions_from_name(self):
+        event = events.LoadFromNameEvent(self.loader, __name__+'.func', None)
+        suite = self.session.hooks.loadTestsFromName(event)
+        self.assertNotEqual(suite, None)
+
+    def test_ignores_test_methods_from_name(self):
+        # Should ignore test methods even when specified directly
+        event = events.LoadFromNameEvent(self.loader, __name__+'.Case.test_method', None)
+        suite = self.session.hooks.loadTestsFromName(event)
+        self.assertEqual(suite, None)
+
+    def test_ignores_decorated_test_methods_from_name(self):
+        # Should ignore test methods even when they are of FunctionType
+        event = events.LoadFromNameEvent(self.loader, __name__+'.Case.test_patched', None)
+        suite = self.session.hooks.loadTestsFromName(event)
+        self.assertEqual(suite, None)
+
+
+def func():
+    pass
+
+def dummy():
+    pass
+
+class Case(unittest.TestCase):
+    __test__ = False # do not run this
+
+    def test_method(self):
+        pass
+
+    @mock.patch(__name__+'.dummy')
+    def test_patched(self, mock):
+        pass