当前位置: 首页>>代码示例>>Python>>正文


Python TestLoader.loadTestsFromName方法代码示例

本文整理汇总了Python中unittest.TestLoader.loadTestsFromName方法的典型用法代码示例。如果您正苦于以下问题:Python TestLoader.loadTestsFromName方法的具体用法?Python TestLoader.loadTestsFromName怎么用?Python TestLoader.loadTestsFromName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.TestLoader的用法示例。


在下文中一共展示了TestLoader.loadTestsFromName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestGroup

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
class TestGroup(object):
    def __init__(self, name, classnames=None, groupSetUp=lambda:None, groupTearDown=lambda:None):
        self.name = name
        self._classes = {}
        for classname in (classnames or []):
            self._loadClass(classname)
        self._loader = TestLoader()
        self.setUp = groupSetUp
        self.tearDown = groupTearDown

    def _loadClass(self, classname):
        moduleName, className = classname.rsplit('.', 1)
        cls = getattr(__import__(moduleName, globals(), locals(), [className]), className)
        self._classes[className] = cls

    def createSuite(self, testnames=None):
        if not testnames:
            testnames = sorted(self._classes.keys())
        suite = TestSuite()
        for testname in testnames:
            testcase = testname.split('.')
            testclass = self._classes.get(testcase[0], None)
            if not testclass:
                continue
            if len(testcase) == 1:
                suite.addTest(self._loader.loadTestsFromTestCase(testclass))
            else:
                suite.addTest(self._loader.loadTestsFromName(testcase[1], testclass))
        return suite
开发者ID:seecr,项目名称:meresco-triplestore,代码行数:31,代码来源:testrunner.py

示例2: build_suite

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        '''
        Override the base class method to return a suite consisting of all
        TestCase subclasses throughought the whole project.
        '''
        if test_labels:
            suite = TestSuite()
        else:
            suite = DjangoTestSuiteRunner.build_suite(
                self, test_labels, extra_tests, **kwargs
            )
        added_test_classes = set(t.__class__ for t in suite)

        loader = TestLoader()
        for fname in _get_module_names(os.getcwd()):
            module = _import(_to_importable_name(fname))
            for test_class in _get_testcases(module):

                if test_class in added_test_classes:
                    continue

                for method_name in loader.getTestCaseNames(test_class):
                    testname = '.'.join([
                        module.__name__, test_class.__name__, method_name
                    ])
                    if self._test_matches(testname, test_labels):
                        suite.addTest(loader.loadTestsFromName(testname))
                        added_test_classes.add(test_class)

        return reorder_suite(suite, (TestCase,))
开发者ID:bloodearnest,项目名称:extending_unittest,代码行数:32,代码来源:all_dirs_runner.py

示例3: main

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [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
开发者ID:HydroLogic,项目名称:ocgis,代码行数:35,代码来源:run_simple.py

示例4: find_tests_and_apps

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
    def find_tests_and_apps(self, label):
        """Construct a test suite of all test methods with the specified name.
        Returns an instantiated test suite corresponding to the label provided.
        """

        tests = []
        from unittest import TestLoader

        loader = TestLoader()

        from django.db.models import get_app, get_apps

        for app_models_module in get_apps():
            app_name = app_models_module.__name__.rpartition(".")[0]
            if app_name == label:
                from django.test.simple import build_suite

                tests.append(build_suite(app_models_module))

            from django.test.simple import get_tests

            app_tests_module = get_tests(app_models_module)

            for sub_module in [m for m in app_models_module, app_tests_module if m is not None]:

                # print "Checking for %s in %s" % (label, sub_module)

                for name in dir(sub_module):
                    obj = getattr(sub_module, name)
                    import types

                    if isinstance(obj, (type, types.ClassType)) and issubclass(obj, unittest.TestCase):

                        test_names = loader.getTestCaseNames(obj)
                        # print "Checking for %s in %s.%s" % (label, obj, test_names)
                        if label in test_names:
                            tests.append(loader.loadTestsFromName(label, obj))

                try:
                    module = sub_module
                    from django.test import _doctest as doctest
                    from django.test.testcases import DocTestRunner

                    doctests = doctest.DocTestSuite(module, checker=self.doctestOutputChecker, runner=DocTestRunner)
                    # Now iterate over the suite, looking for doctests whose name
                    # matches the pattern that was given
                    for test in doctests:
                        if test._dt_test.name in (
                            "%s.%s" % (module.__name__, ".".join(parts[1:])),
                            "%s.__test__.%s" % (module.__name__, ".".join(parts[1:])),
                        ):
                            tests.append(test)
                except TypeError as e:
                    raise Exception("%s appears not to be a module: %s" % (module, e))
                except ValueError:
                    # No doctests found.
                    pass

        # If no tests were found, then we were given a bad test label.
        if not tests:
            raise ValueError(("Test label '%s' does not refer to a " + "test method or app") % label)

        # Construct a suite out of the tests that matched.
        return unittest.TestSuite(tests)
开发者ID:pombredanne,项目名称:intranet-binder,代码行数:66,代码来源:testing.py

示例5: TestSuite

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
from unittest import TestSuite, TestLoader

TEST_MODULES = [
    'saleor.cart.tests',
    'saleor.checkout.tests',
    'saleor.communication.tests',
    'saleor.core.tests',
    #'saleor.delivery.tests',
    'saleor.order.tests',
    #'saleor.payment.tests',
    #'saleor.product.tests',
    'saleor.registration.tests',
    'saleor.userprofile.tests']

suite = TestSuite()
loader = TestLoader()
for module in TEST_MODULES:
    suite.addTests(loader.loadTestsFromName(module))
开发者ID:GeorgeLubaretsi,项目名称:saleor,代码行数:20,代码来源:tests.py

示例6: map

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
    modules = []
    # Find top level modules for all test profiles
    for p in main['tests']:
        prefixes = map(lambda x: x[:x.find('.')] if x.find('.') > -1 else x,
                       map(lambda x: x if isinstance(x, basestring) else x['tests'],main['tests'][p]))
        modules.extend(prefixes)
    # Eliminate duplicates
    modules = list(set(modules))
    t = TestLoader()

    all_tests = []
    # Get every test of every module
    for m in modules:
        __import__(m + '.tests')
        all_tests.extend(get_tests(t.loadTestsFromName(m + '.tests')))

    untested_all = list(all_tests)
    for p in main['tests']:
        untested = list(all_tests)
        # Remove every test of this profile from the untested list
        for t in main['tests'][p]:
            if isinstance(t, dict):
                t = t['tests']
            untested = filter(lambda x: x.find(t) != 0,untested)
            untested_all = filter(lambda x: x.find(t) != 0,untested_all)
        # Now the untested list contains only tests not regarded in this profile
        if len(untested) == 0:
            print '\033[92mProfile',p,'tests everything!\033[0m\n'
        else:
            print '\033[93mProfile',p,'misses',len(untested),'of',len(all_tests),'tests:\033[0m\n',untested,'\n'
开发者ID:ulf,项目名称:django-deptest,代码行数:32,代码来源:deptest.py

示例7: fail

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]

def fail(msg, code=1):
    sys.stderr.write("ERROR - %s\n" % msg)
    sys.exit(code)

if len(sys.argv) < 2:
    fail("expected <name1> [<name2> ... <nameN>]")

tests = []
loader = TestLoader()
for i, name in enumerate(sys.argv[1:]):
    # detects end of arguments
    if name == "-":
        del sys.argv[0:i]
        break
        
    print "loading tests from %s" % name
    __import__(name)
    tests.extend(loader.loadTestsFromName(name))

if not tests:
    fail("no tests found")

# debugging argv handling
print "sys.argv: %s" % sys.argv

logging.basicConfig(level=logging.DEBUG)

suite = TestSuite(tests)
TextTestRunner(verbosity=2).run(suite)
开发者ID:mhawthorne,项目名称:antonym,代码行数:32,代码来源:runner.py

示例8: test_suite

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
def test_suite():
    testloader = TestLoader()
    return testloader.loadTestsFromName('tests.aksyfs.tests.test_aksyfuse')
开发者ID:svanzoest,项目名称:aksy,代码行数:5,代码来源:test_aksyfuse.py

示例9: discoverTestModules

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import loadTestsFromName [as 别名]
        path = os.path.join(dirpath, name)
        if os.path.isdir(path):
            modules += discoverTestModules(path)
        elif name.endswith(".py") and name.startswith("test_"):
            modules.append(path.replace(".py", "").replace("/", "."))
    return modules

loader = TestLoader()
alltests = TestSuite()

for module in discoverTestModules("Pegasus/test"):
    # If not testing service, skip service test modules
    if not test_service and module.startswith("Pegasus.test.service"):
        continue

    # First, try importing the module to make sure it works
    __import__(module)

    # Now load the tests from the module
    suite = loader.loadTestsFromName(module)
    alltests.addTest(suite)

runner = TextTestRunner(verbosity=2)
result = runner.run(alltests)

if result.wasSuccessful():
    sys.exit(0)
else:
    sys.exit(1)

开发者ID:augre,项目名称:pegasus,代码行数:31,代码来源:test.py


注:本文中的unittest.TestLoader.loadTestsFromName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。