timeout.py 文件源码

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

项目:intel-iot-refkit 作者: intel 项目源码 文件源码
def set_timeout(testsuite, seconds=None):
    """
    add timout to test case if it didn't have one,
    @param testsuite testsuite form loader()
    @param seconds: timeout seconds
    @return: updated testsuite
    """
    def _testset(testsuite):
        """interate tcs in testsuite"""
        for each in testsuite:
            if not isinstance(each, unittest.BaseTestSuite):
                yield each
            else:
                for each2 in _testset(each):
                    yield  each2

    if seconds:
        for tc in _testset(testsuite):
            assert hasattr(tc, "_testMethodName"), \
                "%s is not an unittest.TestCase object"
            testMethod = getattr(tc, tc._testMethodName)
            test_func = testMethod.im_func
            if not hastimeout(test_func):
                tc.run = timeout(seconds)(tc.run)
    return testsuite
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号