for case in case_name: mod = importlib.import_module(‘tests.‘+case)#动态导入tests目录下的case clas = getattr(mod, case)#实例化case atts = dir(clas)#获得case属性 for att in atts: if ‘test_‘ in att: print(‘%s running......‘ % att) test = getattr(clas(), att)()#运行含有‘test_’的方法 print(‘%s is complete‘ % att)
原文:https://www.cnblogs.com/gexbooks/p/10918784.html