python 动态添加测试case
静态函数-加setattr 函数添加动态函数 根据参数。
import unittest
class TestFkMath(unittest.TestCase):
bar = 1
def test_one(self):
self.assertEqual(1,1)
def action(self,arg1):
print("action %s"%(arg1))
@staticmethod
def getTestFunc(arg1):
def func(self):
self.action(arg1)
return func
if __name__ == "__main__":
setattr(TestFkMath,'test_two',TestFkMath.getTestFunc('two'))
setattr(TestFkMath,'test_three',TestFkMath.getTestFunc('three'))
print(getattr(TestFkMath,'bar'))
unittest.main()