當前位置: 首頁>>代碼示例>>Python>>正文


Python tests.test_classes方法代碼示例

本文整理匯總了Python中tests.test_classes方法的典型用法代碼示例。如果您正苦於以下問題:Python tests.test_classes方法的具體用法?Python tests.test_classes怎麽用?Python tests.test_classes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tests的用法示例。


在下文中一共展示了tests.test_classes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: import tests [as 別名]
# 或者: from tests import test_classes [as 別名]
def run(matcher=None, repeat=1, ci=False):
    """
    Runs the tests

    :param matcher:
        A unicode string containing a regular expression to use to filter test
        names by. A value of None will cause no filtering.

    :param repeat:
        An integer - the number of times to run the tests

    :param ci:
        A bool, indicating if the tests are being run as part of CI

    :return:
        A bool - if the tests succeeded
    """

    _preload(requires_oscrypto, not ci)

    warnings.filterwarnings("error")

    loader = unittest.TestLoader()
    # We have to manually track the list of applicable tests because for
    # some reason with Python 3.4 on Windows, the tests in a suite are replaced
    # with None after being executed. This breaks the repeat functionality.
    test_list = []
    for test_class in test_classes():
        if matcher:
            names = loader.getTestCaseNames(test_class)
            for name in names:
                if re.search(matcher, name):
                    test_list.append(test_class(name))
        else:
            test_list.append(loader.loadTestsFromTestCase(test_class))

    stream = sys.stdout
    verbosity = 1
    if matcher and repeat == 1:
        verbosity = 2
    elif repeat > 1:
        stream = StringIO()

    for _ in range(0, repeat):
        suite = unittest.TestSuite()
        for test in test_list:
            suite.addTest(test)
        result = unittest.TextTestRunner(stream=stream, verbosity=verbosity).run(suite)

        if len(result.errors) > 0 or len(result.failures) > 0:
            if repeat > 1:
                print(stream.getvalue())
            return False

        if repeat > 1:
            stream.truncate(0)

    return True 
開發者ID:wbond,項目名稱:oscrypto,代碼行數:60,代碼來源:tests.py


注:本文中的tests.test_classes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。