本文整理汇总了Python中unittest.defaultTestLoader方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.defaultTestLoader方法的具体用法?Python unittest.defaultTestLoader怎么用?Python unittest.defaultTestLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest
的用法示例。
在下文中一共展示了unittest.defaultTestLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def run(self):
"""Run the test suite."""
try:
import unittest2 as unittest
except ImportError:
import unittest
if self.verbose:
verbosity=1
else:
verbosity=0
loader = unittest.defaultTestLoader
suite = unittest.TestSuite()
if self.test_suite == self.DEFAULT_TEST_SUITE:
for test_module in loader.discover('.'):
suite.addTest(test_module)
else:
suite.addTest(loader.loadTestsFromName(self.test_suite))
result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
if not result.wasSuccessful():
sys.exit(1)
示例2: build_suite
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def build_suite(suite, names):
# Determine the root directory of the source code files. This is
# used for finding doctest files specified relative to that root.
project_root = os.path.join(os.path.dirname(__file__), "..", "..")
project_root = os.path.abspath(project_root)
# Load test cases from specified names.
loader = unittest.defaultTestLoader
for name in names:
if name.startswith("."):
name = "dragonfly.test" + name
suite.addTests(loader.loadTestsFromName(name))
elif name.startswith("doc:"):
path = name[4:]
path = os.path.join(project_root, *path.split("/"))
path = os.path.abspath(path)
suite.addTests(doctest.DocFileSuite(path))
else:
raise Exception("Invalid test name: %r." % (name,))
return suite
示例3: discover_and_run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def discover_and_run_tests():
import os
import sys
import unittest
# get setup.py directory
setup_file = sys.modules['__main__'].__file__
setup_dir = os.path.abspath(os.path.dirname(setup_file))
# use the default shared TestLoader instance
test_loader = unittest.defaultTestLoader
# use the basic test runner that outputs to sys.stderr
test_runner = unittest.TextTestRunner()
# automatically discover all tests
# NOTE: only works for python 2.7 and later
test_suite = test_loader.discover(setup_dir)
# run the test suite
result = test_runner.run(test_suite)
if len(result.failures) + len(result.errors) > 0:
exit(1)
示例4: test_mock_patch_cleanup_on_teardown
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def test_mock_patch_cleanup_on_teardown(self):
# create an object and save its reference
class Sub(object):
pass
obj = Sub()
obj.value = obj.backup = object()
# patch the object
mock.patch.object(obj, 'value').start()
self.assertNotEqual(obj.backup, obj.value)
# run a test case
loader = unittest.defaultTestLoader
suite = loader.loadTestsFromTestCase(self.FakeTestCase)
suite.run(unittest.TestResult())
# check that mock patches are cleaned up
self.assertEqual(obj.backup, obj.value)
示例5: django_json_test_runner
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def django_json_test_runner(request):
from django.http import HttpResponse
response = HttpResponse()
response["Content-Type"] = "text/javascript"
test_name = request.REQUEST.get("name")
_load_default_test_modules(_LOCAL_DJANGO_TEST_DIR)
suite = unittest.defaultTestLoader.loadTestsFromName(test_name)
runner = JsonTestRunner()
_run_test_suite(runner, suite)
runner.result.render_to(response)
return response
########################################################
示例6: get
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def get(self):
self.response.headers["Content-Type"] = "text/javascript"
test_name = self.request.get("name")
_load_default_test_modules(_LOCAL_TEST_DIR)
suite = unittest.defaultTestLoader.loadTestsFromName(test_name)
runner = JsonTestRunner()
_run_test_suite(runner, suite)
runner.result.render_to(self.response.out)
# This is not used by the HTML page, but it may be useful for other client test runners.
示例7: _create_suite
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def _create_suite(package_name, test_name, test_dir):
loader = unittest.defaultTestLoader
suite = unittest.TestSuite()
error = None
try:
if not package_name and not test_name:
modules = _load_default_test_modules(test_dir)
for module in modules:
suite.addTest(loader.loadTestsFromModule(module))
elif test_name:
_load_default_test_modules(test_dir)
suite.addTest(loader.loadTestsFromName(test_name))
elif package_name:
package = reload(__import__(package_name))
module_names = package.__all__
for module_name in module_names:
suite.addTest(loader.loadTestsFromName('%s.%s' % (package_name, module_name)))
if suite.countTestCases() == 0:
raise Exception("'%s' is not found or does not contain any tests." % \
(test_name or package_name or 'local directory: \"%s\"' % _LOCAL_TEST_DIR))
except Exception:
import traceback
error = traceback.format_exc()
print error
_log_error(error)
return (suite, error)
示例8: load_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def load_tests(loader, standard_tests, pattern):
loader = unittest.defaultTestLoader
if test_unit:
suite = loader.discover(parent_dir)
else:
suite = unittest.TestSuite()
if test_integration:
for test_case in test_cases:
tests = loader.loadTestsFromTestCase(test_case)
suite.addTests(tests)
return suite
示例9: run
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def run():
test_loader = unittest.defaultTestLoader
test_suites = test_loader.discover(os.path.dirname(__file__))
unittest.TextTestRunner(buffer=True).run(test_suites)
#parallel.barrier()
示例10: run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def run_tests(self):
import unittest
test_loader = unittest.defaultTestLoader
test_runner = unittest.TextTestRunner()
test_suite = test_loader.discover(setup_dir)
test_runner.run(test_suite)
示例11: run_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def run_tests():
loader = unittest.defaultTestLoader
suite = _make_test_suite(loader)
exit_code = _run_test_suite(suite)
return exit_code
示例12: additional_tests
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def additional_tests():
setup_file = sys.modules['__main__'].__file__
setup_dir = os.path.abspath(os.path.dirname(setup_file))
test_dir = os.path.join(setup_dir, 'tests')
test_suite = unittest.defaultTestLoader.discover(test_dir)
blacklist = []
if '/home/travis' in __file__:
# Skip some tests that fail on travis-ci
blacklist.append('test_command')
return exclude_tests(test_suite, blacklist)
示例13: test_all
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def test_all():
mpath = os.path.abspath(os.path.join(test_dir, '..'))
sys.path.insert(0, mpath) # so we load dev files before any installation
loader = unittest.defaultTestLoader
tpath = os.path.join(mpath, 'tests')
suite = loader.discover(tpath)
return suite
示例14: run
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def run(self):
import os, sys, unittest
setup_file = sys.modules['__main__'].__file__
setup_dir = os.path.abspath(os.path.dirname(setup_file))
test_loader = unittest.defaultTestLoader
test_runner = unittest.TextTestRunner()
test_suite = test_loader.discover(setup_dir)
test_runner.run(test_suite)
示例15: run
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import defaultTestLoader [as 别名]
def run(self):
build = self.get_finalized_command("build")
build.run()
if self.catch:
unittest.installHandler()
sys.path.insert(0, str(Path(build.build_lib).resolve()))
test_loader = unittest.defaultTestLoader
if self.test_name:
tests = test_loader.loadTestsFromName(self.test_name, None)
else:
tests = test_loader.discover(self.start_dir, self.pattern)
test_runner = unittest.TextTestRunner(
verbosity = self.verbose,
failfast = self.failfast,
buffer = self.buffer
)
test_results = test_runner.run(tests)
del sys.path[0]
if self.exit and not test_results.wasSuccessful():
raise SystemExit()