本文整理汇总了Python中unittest.TestLoader.loadTestsFromModule方法的典型用法代码示例。如果您正苦于以下问题:Python TestLoader.loadTestsFromModule方法的具体用法?Python TestLoader.loadTestsFromModule怎么用?Python TestLoader.loadTestsFromModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestLoader
的用法示例。
在下文中一共展示了TestLoader.loadTestsFromModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestHTMLTestRunner
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
class TestHTMLTestRunner(TestCase):
def setUp(self):
self.suite = TestSuite()
self.loader = TestLoader()
self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestPass))
self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestFail))
self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestBasic))
self.results_output_buffer = StringIO()
HTMLTestRunner(stream=self.results_output_buffer).run(self.suite)
self.byte_output = self.results_output_buffer.getvalue()
def test_SampleTestPass(self):
output1="".join(self.byte_output.split())
output2="".join(SampleTestPass.EXPECTED_RESULT.split())
self.assertGreater(output1.find(output2),0)
@skip("Test Skipping")
def test_SampleTestSkip(self):
self.fail("This error should never be displayed")
def test_SampleTestFail(self):
output1="".join(self.byte_output.split())
output2="".join(SampleTestFail.EXPECTED_RESULT.split())
self.assertGreater(output1.find(output2),0)
def test_SampleTestBasic(self):
output1="".join(self.byte_output.split())
output2="".join(SampleTestBasic.EXPECTED_RESULT.split())
self.assertGreater(output1.find(output2),0)
示例2: loadTestsFromModule
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def loadTestsFromModule(self, module):
"""
Return a suite of all tests cases contained in the given module
"""
tests = [TestLoader.loadTestsFromModule(self,module)]
if hasattr(module, "additional_tests"):
tests.append(module.additional_tests())
if hasattr(module, '__path__'):
for dir in module.__path__:
for file in os.listdir(dir):
if file.endswith('.py') and file!='__init__.py':
if file.lower().startswith('test'):
submodule = module.__name__+'.'+file[:-3]
else:
continue
else:
subpkg = os.path.join(dir,file,'__init__.py')
if os.path.exists(subpkg):
submodule = module.__name__+'.'+file
else:
continue
tests.append(self.loadTestsFromName(submodule))
if len(tests)>1:
return self.suiteClass(tests)
else:
return tests[0] # don't create a nested suite for only one return
示例3: loadTestsFromModule
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def loadTestsFromModule(self, module):
"""Load unit test (skip 'interop' package).
Hacked from the version in 'setuptools.command.test.ScanningLoader'.
"""
tests = []
tests.append(TestLoader.loadTestsFromModule(self,module))
if hasattr(module, '__path__'):
for file in resource_listdir(module.__name__, ''):
if file == 'interop':
# These tests require installing a bunch of extra
# code: see 'src/soaplib/test/README'.
continue
if file.endswith('.py') and file != '__init__.py':
submodule = module.__name__ + '.' + file[:-3]
else:
if resource_exists(
module.__name__, file + '/__init__.py'
):
submodule = module.__name__ + '.' + file
else:
continue
tests.append(self.loadTestsFromName(submodule))
return self.suiteClass(tests)
示例4: all
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def all():
'''
This runs all tests and examples. It is something of a compromise - seems
to be the best solution that's independent of other libraries, doesn't
use the file system (since code may be in a zip file), and keeps the
number of required imports to a minimum.
'''
basicConfig(level=ERROR)
log = getLogger('lepl._test.all.all')
suite = TestSuite()
loader = TestLoader()
runner = TextTestRunner(verbosity=4)
for module in ls_modules(lepl, MODULES):
log.debug(module.__name__)
suite.addTest(loader.loadTestsFromModule(module))
result = runner.run(suite)
print('\n\n\n----------------------------------------------------------'
'------------\n')
if version[0] == '2':
print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} '
.format(len(result.failures), len(result.errors)))
assert 2 <= len(result.failures) <= 5, len(result.failures)
assert 1 <= len(result.errors) <= 2, len(result.errors)
target = TOTAL - NOT_DISTRIBUTED - NOT_3
else:
print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
.format(len(result.failures), len(result.errors)))
assert 0 <= len(result.failures) <= 1, len(result.failures)
assert 0 <= len(result.errors) <= 0, len(result.errors)
target = TOTAL - NOT_DISTRIBUTED
print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
assert result.testsRun == target, result.testsRun
print('\nLooks OK to me!\n\n')
示例5: loadTestsFromModule
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def loadTestsFromModule(self, module):
"""Return a suite of all tests cases contained in the given module
If the module is a package, load tests from all the modules in it.
If the module has an ``additional_tests`` function, call it and add
the return value to the tests.
"""
tests = []
if module.__name__ != 'setuptools.tests.doctest': # ugh
tests.append(TestLoader.loadTestsFromModule(self, module))
if hasattr(module, "additional_tests"):
tests.append(module.additional_tests())
if hasattr(module, '__path__'):
for file in resource_listdir(module.__name__, ''):
if file.endswith('.py') and file != '__init__.py':
submodule = module.__name__ + '.' + file[:-3]
else:
if resource_exists(module.__name__, file + '/__init__.py'):
submodule = module.__name__+'.'+file
else:
continue
tests.append(self.loadTestsFromName(submodule))
if len(tests) != 1:
return self.suiteClass(tests)
else:
return tests[0] # don't create a nested suite for only one return
示例6: search
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def search(path, prefix=''):
loader = TestLoader()
for _, name, is_pkg in iter_modules(path):
full_name = '{}.{}'.format(prefix, name)
module_path = os.path.join(path[0], name)
if is_pkg:
search([module_path], full_name)
if not is_pkg and name.startswith('test'):
test_module = import_module(full_name)
for suite in loader.loadTestsFromModule(test_module):
for test in suite._tests:
path = '{}.{}.{}'.format(full_name, test.__class__.__name__, test._testMethodName)
rec = {
'ver': '1.0',
'execution': {
'command': 'python -m unittest {}'.format(path),
'recording': find_recording_file(path)
},
'classifier': {
'identifier': path,
'type': get_test_type(test),
}
}
RECORDS.append(rec)
示例7: run_suite
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def run_suite(verbose=False):
loader = TestLoader()
runner = TextTestRunner(verbosity=2 if verbose else 1)
suite = TestSuite()
for mod in get_modules():
suite.addTest(loader.loadTestsFromModule(mod))
runner.run(suite)
return 0
示例8: run_daemon
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def run_daemon(testpath, testname, amqp):
module = load_source(testname, testpath)
loader = TestLoader()
suite = loader.loadTestsFromModule(module)
result = CanopsisTestResult(module.__name__, amqp)
suite.run(result)
result.report()
示例9: run
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def run(self):
address = self.address or 'localhost:10190'
os.environ.setdefault('URLFETCH_ADDR', address)
import pyurlfetch.tests
loader = TestLoader()
t = TextTestRunner()
t.run(loader.loadTestsFromModule(pyurlfetch.tests))
示例10: create_test_suite
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def create_test_suite():
"""create a unittest.TestSuite with available tests"""
from unittest import TestLoader, TestSuite
loader = TestLoader()
suite = TestSuite()
for test_name in available_tests:
exec("from . import " + test_name)
suite.addTests(loader.loadTestsFromModule(eval(test_name)))
return suite
示例11: loadTestsFromModule
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def loadTestsFromModule(self, module):
"""Load unit test for tests directory
"""
tests = list()
tests.append(TestLoader.loadTestsFromModule(self, module))
if hasattr(module, '__path__'):
for file in resource_listdir(module.__name__, ''):
if file.endswith('.py') and file != '__init__.py':
submodule = module.__name__ + '.' + file[:-3]
else:
if resource_exists(module.__name__, file + '/__init__.py'):
submodule = module.__name__ + '.' + file
else:
continue
tests.append(self.loadTestsFromName(submodule))
return self.suiteClass(tests)
示例12: collect_tests
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def collect_tests(path, return_collection, prefix=''):
from unittest import TestLoader
from importlib import import_module
from pkgutil import iter_modules
loader = TestLoader()
for _, name, is_pkg in iter_modules(path):
full_name = '{}.{}'.format(prefix, name)
module_path = os.path.join(path[0], name)
if is_pkg:
collect_tests([module_path], return_collection, full_name)
if not is_pkg and name.startswith('test'):
test_module = import_module(full_name)
for suite in loader.loadTestsFromModule(test_module):
for test in suite._tests: # pylint: disable=protected-access
return_collection.append(
'{}.{}.{}'.format(full_name, test.__class__.__name__, test._testMethodName)) # pylint: disable=protected-access
示例13: run
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def run(self):
appengine_path = self.appengine_path or '/'
extra_paths = [
appengine_path,
os.path.join(appengine_path, 'lib', 'antlr3'),
os.path.join(appengine_path, 'lib', 'django_0_96'),
os.path.join(appengine_path, 'lib', 'fancy_urllib'),
os.path.join(appengine_path, 'lib', 'ipaddr'),
os.path.join(appengine_path, 'lib', 'webob'),
os.path.join(appengine_path, 'lib', 'yaml', 'lib'),
os.path.join(appengine_path, 'lib', 'lib', 'simplejson'),
os.path.join(appengine_path, 'lib', 'lib', 'graphy'),
]
sys.path.extend(extra_paths)
import apptrace.tests
loader = TestLoader()
t = TextTestRunner()
t.run(loader.loadTestsFromModule(apptrace.tests))
示例14: run
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def run(self):
gae_sdk = self.gae_sdk or '/'
extra_paths = [
gae_sdk,
os.path.join(gae_sdk, 'lib', 'antlr3'),
os.path.join(gae_sdk, 'lib', 'django'),
os.path.join(gae_sdk, 'lib', 'fancy_urllib'),
os.path.join(gae_sdk, 'lib', 'ipaddr'),
os.path.join(gae_sdk, 'lib', 'webob'),
os.path.join(gae_sdk, 'lib', 'yaml', 'lib'),
os.path.join(gae_sdk, 'lib', 'simplejson'),
os.path.join(gae_sdk, 'lib', 'graphy'),
]
sys.path.extend(extra_paths)
import gaesynkit.tests
loader = TestLoader()
t = TextTestRunner()
t.run(loader.loadTestsFromModule(gaesynkit.tests))
示例15: all
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromModule [as 别名]
def all():
'''
This runs all tests and examples. It is something of a compromise - seems
to be the best solution that's independent of other libraries, doesn't
use the file system (since code may be in a zip file), and keeps the
number of required imports to a minimum.
'''
#basicConfig(level=DEBUG)
log = getLogger('lepl._test.all.all')
suite = TestSuite()
loader = TestLoader()
runner = TextTestRunner(verbosity=2)
for module in ls_all_tests():
log.debug(module.__name__)
suite.addTest(loader.loadTestsFromModule(module))
result = runner.run(suite)
print('\n\n\n----------------------------------------------------------'
'------------\n')
if version[0] == '2':
print('Expect 4-5 failures + 1 error in Python 2.6: {0:d}, {1:d} '
'(lenient comparison, format variation from address size, '
'unicode ranges, weird string difference)'
.format(len(result.failures), len(result.errors)))
assert 4 <= len(result.failures) <= 5, len(result.failures)
assert 1 <= len(result.errors) <= 1, len(result.errors)
target = TOTAL - 22 - 9 # no bin/cairo tests (22)
else:
print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
'(format variations from address size?)'
.format(len(result.failures), len(result.errors)))
assert 0 <= len(result.failures) <= 1, len(result.failures)
assert 0 <= len(result.errors) <= 0, len(result.errors)
target = TOTAL - 9 # no cairo tests (2), no random (1), no support[3] (6)
print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
assert result.testsRun == target, result.testsRun
print('\nLooks OK to me!\n\n')