Recently, I ' m concentrating on nose plugin development.
Some people would is confused with Some descriptions in http://nose.readthedocs.io/en/latest/plugins/interface.html
Wantfunction (function) return
True to collect the This function as a test, false to prevent it from being collected, and N One if you don ' t care.
Parameters:function–the function object being examined by the selector
Wantmethod (method) return
true to Collec T this method as a test, false to prevent it from being collected, and None if you don ' t care.
Parameters:method (unbound method) –the method object being examined by the selector
what is the different between function and method?
After some experiments, we get the conclusion below:
-function is defined out of class in Python
-method are defined in a class
>>> def A (): Pass
>>> a
<function A at 0x107063aa0>
>>> type (a)
< Type ' function ' >
>>> class A:
... def a (self): pass
>>> a.a
<unbound method a.a>
>>> type (A.A)
<type ' Instancemethod ' >
Import UnitTest
def test_function ():
print "Test_function is invoked by Wantfunction"
class Teststringmethods (unittest. TestCase):
def test_method (self):
print "Test_method is invoked by Wantmethod"