def getTests(filterApplication=""):
root = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "libs"))
suites = {}
for root, dirs, files in os.walk(root):
for file in files:
if file.startswith("__") or file.endswith(".pyc") or not file.lower().startswith("test"):
logger.debug("skipping file for testing {}".format(file))
continue
name = os.path.splitext(os.path.basename(os.path.join(root, file)))[0]
try:
module = imp.load_source(name, os.path.realpath(os.path.join(root, file)))
except ImportError as e:
logger.info("import failed for {}".format(file), exc_info=True)
continue
for member in inspect.getmembers(module, predicate=inspect.isclass):
cl = member[1]
try:
app = cl.application
except AttributeError:
logger.debug("class not a test skipping :{}".format(cl))
continue
if app in suites:
suites[app].addTest(unittest.makeSuite(cl))
continue
if not filterApplication:
newSuite = unittest.makeSuite(cl)
suites[app] = newSuite
elif app == filterApplication:
newSuite = unittest.makeSuite(cl)
suites[app] = newSuite
return suites
评论列表
文章目录