本文整理汇总了Python中unittest.TestLoader.addTests方法的典型用法代码示例。如果您正苦于以下问题:Python TestLoader.addTests方法的具体用法?Python TestLoader.addTests怎么用?Python TestLoader.addTests使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestLoader
的用法示例。
在下文中一共展示了TestLoader.addTests方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_tests
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
def _run_tests(self):
secrets_current = pjoin(self._dir, 'libcloud/test', 'secrets.py')
secrets_dist = pjoin(self._dir, 'libcloud/test', 'secrets.py-dist')
if not os.path.isfile(secrets_current):
print("Missing " + secrets_current)
print("Maybe you forgot to copy it from -dist:")
print("cp libcloud/test/secrets.py-dist libcloud/test/secrets.py")
sys.exit(1)
mtime_current = os.path.getmtime(secrets_current)
mtime_dist = os.path.getmtime(secrets_dist)
if mtime_dist > mtime_current:
print("It looks like test/secrets.py file is out of date.")
print("Please copy the new secrets.py-dist file over otherwise" +
" tests might fail")
if pre_python26:
missing = []
# test for dependencies
try:
import simplejson
simplejson # silence pyflakes
except ImportError:
missing.append("simplejson")
try:
import ssl
ssl # silence pyflakes
except ImportError:
missing.append("ssl")
if missing:
print("Missing dependencies: " + ", ".join(missing))
sys.exit(1)
testfiles = []
for test_path in TEST_PATHS:
for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
testfiles.append('.'.join(
[test_path.replace('/', '.'), splitext(basename(t))[0]]))
tests = TestLoader().loadTestsFromNames(testfiles)
for test_module in DOC_TEST_MODULES:
tests.addTests(doctest.DocTestSuite(test_module))
t = TextTestRunner(verbosity=2)
res = t.run(tests)
return not res.wasSuccessful()
示例2: run
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
def run(self):
'''
Finds all the tests modules in tests/, and runs them.
'''
testfiles = []
for t in glob(pjoin(self._dir, 'tests', '*.py')):
if not t.endswith('__init__.py'):
testfiles.append('.'.join(
['tests', splitext(basename(t))[0]])
)
tests = TestLoader().loadTestsFromNames(testfiles)
import eopayment
tests.addTests(doctest.DocTestSuite(eopayment))
t = TextTestRunner(verbosity=4)
t.run(tests)
示例3: _run_tests
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
def _run_tests(self):
secrets = pjoin(self._dir, 'test', 'secrets.py')
if not os.path.isfile(secrets):
print "Missing %s" % (secrets)
print "Maybe you forgot to copy it from -dist:"
print " cp test/secrets.py-dist test/secrets.py"
sys.exit(1)
pre_python26 = (sys.version_info[0] == 2
and sys.version_info[1] < 6)
if pre_python26:
missing = []
# test for dependencies
try:
import simplejson
simplejson # silence pyflakes
except ImportError:
missing.append("simplejson")
try:
import ssl
ssl # silence pyflakes
except ImportError:
missing.append("ssl")
if missing:
print "Missing dependencies: %s" % ", ".join(missing)
sys.exit(1)
testfiles = []
for test_path in TEST_PATHS:
for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
testfiles.append('.'.join(
[test_path.replace('/', '.'), splitext(basename(t))[0]]))
tests = TestLoader().loadTestsFromNames(testfiles)
for test_module in DOC_TEST_MODULES:
tests.addTests(doctest.DocTestSuite(test_module))
t = TextTestRunner(verbosity = 2)
res = t.run(tests)
return not res.wasSuccessful()
示例4: discover_tests
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
def discover_tests(start_dir, labels=[], pattern='test*.py'):
"""Discovers tests in a given module filtered by labels. Supports
short-cut labels as defined in :func:`find_shortcut_labels`.
:param start_dir:
Name of directory to begin looking in
:param labels:
Optional list of labels to filter the tests by
:returns:
:class:`TestSuite` with tests
"""
shortcut_labels = []
full_labels = []
for label in labels:
if label.startswith('='):
shortcut_labels.append(label)
else:
full_labels.append(label)
if not full_labels and not shortcut_labels:
# no labels, get everything
return TestLoader().discover(start_dir, pattern=pattern)
shortcut_tests = []
if shortcut_labels:
suite = TestLoader().discover(start_dir, pattern=pattern)
shortcut_tests = find_shortcut_tests(suite, shortcut_labels)
if full_labels:
suite = TestLoader().loadTestsFromNames(full_labels)
suite.addTests(shortcut_tests)
else:
# only have shortcut labels
suite = TestSuite(shortcut_tests)
return suite
示例5: TestLoader
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
import unittest
from unittest import TestLoader
suite = TestLoader().discover('base')
suite.addTests(TestLoader().discover('sdl'))
suite.addTests(TestLoader().discover('shapes'))
suite.addTests(TestLoader().discover('renderer'))
unittest.TextTestRunner(verbosity=5).run(suite)
示例6: TestLoader
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
import unittest
from unittest import TestLoader
suite = TestLoader().discover('base')
suite.addTests(TestLoader().discover('sdl'))
unittest.TextTestRunner(verbosity=5).run(suite)
示例7: _run_tests
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import addTests [as 别名]
def _run_tests(self):
secrets_current = pjoin(self._dir, 'libcloud/test', 'secrets.py')
secrets_dist = pjoin(self._dir, 'libcloud/test', 'secrets.py-dist')
if not os.path.isfile(secrets_current):
print("Missing " + secrets_current)
print("Maybe you forgot to copy it from -dist:")
print("cp libcloud/test/secrets.py-dist libcloud/test/secrets.py")
sys.exit(1)
mtime_current = os.path.getmtime(secrets_current)
mtime_dist = os.path.getmtime(secrets_dist)
if mtime_dist > mtime_current:
print("It looks like test/secrets.py file is out of date.")
print("Please copy the new secrets.py-dist file over otherwise" +
" tests might fail")
if PY2_pre_26:
missing = []
# test for dependencies
try:
import simplejson
simplejson # silence pyflakes
except ImportError:
missing.append("simplejson")
try:
import ssl
ssl # silence pyflakes
except ImportError:
missing.append("ssl")
if missing:
print("Missing dependencies: " + ", ".join(missing))
sys.exit(1)
testfiles = []
for test_path in TEST_PATHS:
for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
testfiles.append('.'.join(
[test_path.replace('/', '.'), splitext(basename(t))[0]]))
# Test loader simply throws "'module' object has no attribute" error
# if there is an issue with the test module so we manually try to
# import each module so we get a better and more friendly error message
for test_file in testfiles:
try:
__import__(test_file)
except Exception:
e = sys.exc_info()[1]
print('Failed to import test module "%s": %s' % (test_file,
str(e)))
raise e
tests = TestLoader().loadTestsFromNames(testfiles)
for test_module in DOC_TEST_MODULES:
tests.addTests(doctest.DocTestSuite(test_module))
t = TextTestRunner(verbosity=2)
res = t.run(tests)
return not res.wasSuccessful()