使用场景:将方法添加到列表中,返回列表使用ddt进行数据驱动传参时,列表中的方法如果按照常规的写法就会被调用
class Test():
@classmethod
def a(cls):
return "method a"
@classmethod
def b(cls):
return "method b"
@classmethod
def c(cls):
return "method c"
def test():
return [Test().a, Test().b, Test().c]
if __name__ == '__main__':
for method in test():
print("this method is " + method.__call__())
此时列表中只放方法名,不要在此时调用,在下面遍历的时候可以使用__call__()方法进行调用,打印名字就是 方法名__name__,类方法和实例方法都可以的