本文整理汇总了Python中unittest.TestSuite.run方法的典型用法代码示例。如果您正苦于以下问题:Python TestSuite.run方法的具体用法?Python TestSuite.run怎么用?Python TestSuite.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestSuite
的用法示例。
在下文中一共展示了TestSuite.run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from unittest import TestSuite [as 别名]
# 或者: from unittest.TestSuite import run [as 别名]
def main():
modules = ['test_360', 'test_dependencies', 'test_optional_dependencies', 'test_simple']
simple_suite = TestSuite()
loader = TestLoader()
result = TestResult()
for module in modules:
suite = loader.loadTestsFromName(module)
simple_suite.addTest(suite)
print
print 'Running simple test suite...'
print
simple_suite.run(result)
print
print 'Ran {0} tests.'.format(result.testsRun)
print
if len(result.errors) > 0:
print '#########################################################'
print 'There are {0} errors. See below for tracebacks:'.format(len(result.errors))
print '#########################################################'
print
for error in result.errors:
print error[1]
print
print '#########################################################'
print 'There are {0} errors. See above for tracebacks.'.format(len(result.errors))
print '#########################################################'
else:
print 'All tests passed.'
print
示例2: selftest
# 需要导入模块: from unittest import TestSuite [as 别名]
# 或者: from unittest.TestSuite import run [as 别名]
def selftest(logger):
selftest_started = time.perf_counter()
result = SelfTestResult()
test_suite = TestSuite()
for test_case in SELFTEST_CASES:
test_suite.addTest(defaultTestLoader.loadTestsFromTestCase(test_case))
test_suite.run(result)
result.log_results(logger)
successful_tests = result.successful_test_count()
count_mismatch = successful_tests != SELFTEST_COUNT
if result.wasSuccessful() and count_mismatch:
# only print this if all tests succeeded
logger.error("self test count (%d != %d) mismatch, either test discovery is broken or a test was added "
"without updating borg.selftest",
successful_tests, SELFTEST_COUNT)
if not result.wasSuccessful() or count_mismatch:
logger.error("self test failed\n"
"This is a bug either in Borg or in the package / distribution you use.")
sys.exit(2)
assert False, "sanity assertion failed: ran beyond sys.exit()"
selftest_elapsed = time.perf_counter() - selftest_started
logger.debug("%d self tests completed in %.2f seconds", successful_tests, selftest_elapsed)
示例3: TestLoader
# 需要导入模块: from unittest import TestSuite [as 别名]
# 或者: from unittest.TestSuite import run [as 别名]
test_modules = [test_core, test_csv, test_database, test_datatypes, test_dispatcher,
test_gettext, test_handlers, test_html, test_i18n, test_ical, test_odf,
test_rss, test_srx, test_stl, test_tmx, test_uri, test_fs,
test_validators, test_web, test_workflow, test_xliff, test_xml, test_xmlfile]
loader = TestLoader()
if __name__ == '__main__':
usage = '%prog [OPTIONS]'
description = 'Run ikaaro tests'
parser = OptionParser(usage, description=description)
parser.add_option('-m', '--mode', default='standard', help='tests mode')
options, args = parser.parse_args()
suite = TestSuite()
for module in test_modules:
suite.addTest(loader.loadTestsFromModule(module))
if options.mode == 'standard':
ret = TextTestRunner(verbosity=1).run(suite)
elif options.mode == 'junitxml':
path = get_abspath('./junit.xml')
print('Result is here: %s' % path)
f = file(path, 'wb')
result = JUnitXmlResult(f)
result.startTestRun()
ret = suite.run(result)
result.stopTestRun()
exit_code = not ret.wasSuccessful()
exit(exit_code)
示例4: TestSuite
# 需要导入模块: from unittest import TestSuite [as 别名]
# 或者: from unittest.TestSuite import run [as 别名]
from Applications.Unittests import module1, module2, module3
__author__ = 'Xavier ROSSET'
__maintainer__ = 'Xavier ROSSET'
__email__ = '[email protected]'
__status__ = "Production"
# ==========================
# Define French environment.
# ==========================
if sys.platform.startswith("win"):
locale.setlocale(locale.LC_ALL, ("french", "fr_FR.ISO8859-1"))
elif sys.platform.startswith("lin"):
locale.setlocale(locale.LC_ALL, "fr_FR.utf8")
# ============
# Main script.
# ============
exit_code = {False: 1, True: 0}
suite, loader, result = TestSuite(), TestLoader(), TestResult()
suite.addTests(loader.loadTestsFromModule(module1))
suite.addTests(loader.loadTestsFromModule(module2))
suite.addTests(loader.loadTestsFromModule(module3))
if sys.platform.startswith("win"):
from Applications.Unittests import module4, module5
suite.addTests(loader.loadTestsFromModule(module4))
suite.addTests(loader.loadTestsFromModule(module5))
suite.run(result)
sys.exit(exit_code[result.wasSuccessful()])