unittestBase.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:zoocore 作者: dsparrow27 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号