I haven't investigated since when it has been broken.
The versions of unittest and nose might be relevant.

Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/tests/test_lib.py                          | 24 ++++++++++++++++++++++++
 ryu/tests/unit/ofproto/test_parser.py          |  5 ++---
 ryu/tests/unit/ofproto/test_parser_compat.py   |  6 ++----
 ryu/tests/unit/ofproto/test_parser_ofpmatch.py |  7 +++----
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/ryu/tests/test_lib.py b/ryu/tests/test_lib.py
index 49922b4..562e9f9 100644
--- a/ryu/tests/test_lib.py
+++ b/ryu/tests/test_lib.py
@@ -1,7 +1,24 @@
+# Copyright (C) 2013,2014,2015 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013,2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 import gettext
 import os
 import unittest
 import sys
+import types
 import logging
 
 from nose import result
@@ -240,3 +257,10 @@ def run_tests(c=None):
                            verbosity=c.verbosity,
                            config=c)
     return not core.run(config=c, testRunner=runner)
+
+
+def add_method(cls, method_name, method):
+    """Add the method to the class dynamically, keeping unittest/nose happy."""
+    method.func_name = method_name
+    method.__name__ = method_name
+    setattr(cls, method_name, types.MethodType(method, None, cls))
diff --git a/ryu/tests/unit/ofproto/test_parser.py 
b/ryu/tests/unit/ofproto/test_parser.py
index c197b9e..a567039 100644
--- a/ryu/tests/unit/ofproto/test_parser.py
+++ b/ryu/tests/unit/ofproto/test_parser.py
@@ -27,6 +27,7 @@ from ryu.ofproto import ofproto_v1_2
 from ryu.ofproto import ofproto_v1_3
 from ryu.ofproto import ofproto_v1_4
 from ryu.ofproto import ofproto_v1_5
+from ryu.tests import test_lib
 import json
 
 
@@ -257,9 +258,7 @@ def _add_tests():
             print('adding %s ...' % method_name)
             f = functools.partial(_run, name=method_name, wire_msg=wire_msg,
                                   json_str=json_str)
-            f.func_name = method_name
-            f.__name__ = method_name
-            setattr(Test_Parser, method_name, f)
+            test_lib.add_method(Test_Parser, method_name, f)
             cases.add(method_name)
             n_added += 1
         assert n_added > 0
diff --git a/ryu/tests/unit/ofproto/test_parser_compat.py 
b/ryu/tests/unit/ofproto/test_parser_compat.py
index 7ebdf98..cacae58 100644
--- a/ryu/tests/unit/ofproto/test_parser_compat.py
+++ b/ryu/tests/unit/ofproto/test_parser_compat.py
@@ -25,6 +25,7 @@ from ryu.ofproto import ofproto_v1_2_parser
 from ryu.ofproto import ofproto_v1_3_parser
 
 from ryu.lib import addrconv
+from ryu.tests import test_lib
 from struct import unpack
 
 
@@ -148,9 +149,6 @@ def _add_tests():
         print('adding %s ...' % method_name)
         f = functools.partial(_run, name=method_name,
                               ofpp=ofpp)
-        f.func_name = method_name
-        f.__name__ = method_name
-        cls = Test_Parser_Compat
-        setattr(cls, method_name, f)
+        test_lib.add_method(Test_Parser_Compat, method_name, f)
 
 _add_tests()
diff --git a/ryu/tests/unit/ofproto/test_parser_ofpmatch.py 
b/ryu/tests/unit/ofproto/test_parser_ofpmatch.py
index 2436b93..86da289 100644
--- a/ryu/tests/unit/ofproto/test_parser_ofpmatch.py
+++ b/ryu/tests/unit/ofproto/test_parser_ofpmatch.py
@@ -30,6 +30,7 @@ from ryu.ofproto import ofproto_v1_2
 from ryu.ofproto import ofproto_v1_3
 from ryu.ofproto import ofproto_v1_2_parser
 from ryu.ofproto import ofproto_v1_3_parser
+from ryu.tests import test_lib
 
 
 class Test_Parser_OFPMatch(unittest.TestCase):
@@ -238,9 +239,7 @@ def _add_tests():
                         print('adding %s ...' % method_name)
                         f = functools.partial(_run, name=method_name,
                                               ofpp=ofpp, d=d, domask=domask)
-                        f.func_name = method_name
-                        f.__name__ = method_name
-                        cls = Test_Parser_OFPMatch
-                        setattr(cls, method_name, f)
+                        test_lib.add_method(Test_Parser_OFPMatch,
+                                            method_name, f)
 
 _add_tests()
-- 
2.2.1


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to