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


Python TestLoader.getTestCaseNames方法代码示例

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


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

示例1: build_suite

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [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

示例2: collect

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
    def collect(self):
        from unittest import TestLoader

        cls = self.obj
        if not getattr(cls, "__test__", True):
            return
        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = TestLoader()
        module = self.getparent(Module).obj
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            if not getattr(x, "__test__", True):
                continue
            funcobj = getattr(x, "im_func", x)
            transfer_markers(funcobj, cls, module)
            yield TestCaseFunction(name, parent=self, callobj=funcobj)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, "runTest", None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction("runTest", parent=self)
开发者ID:kalekundert,项目名称:pytest,代码行数:27,代码来源:unittest.py

示例3: collect

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
    def collect(self):
        from unittest import TestLoader

        cls = self.obj
        if not getattr(cls, "__test__", True):
            return

        skipped = getattr(cls, "__unittest_skip__", False)
        if not skipped:
            self._inject_setup_teardown_fixtures(cls)
            self._inject_setup_class_fixture()

        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = TestLoader()
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            if not getattr(x, "__test__", True):
                continue
            funcobj = getimfunc(x)
            yield TestCaseFunction(name, parent=self, callobj=funcobj)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, "runTest", None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction("runTest", parent=self)
开发者ID:lfernandez55,项目名称:flask_books,代码行数:31,代码来源:unittest.py

示例4: parametrize

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
 def parametrize(testcase_class, users):
     """ Create a suite containing all tests taken from the given
         subclass, passing them the parameter 'client'.
     """
     
     testloader = TestLoader()
     testnames = testloader.getTestCaseNames(testcase_class)
     tests = []
     for name in testnames:
         # Not logged in
         client = Client()
         tests.append(testcase_class(name, client=client))
         
         # Log in users
         for user in users:
             client = Client()
             tests.append(testcase_class(name, client=client, username=user['username'], password=user['password']))
     return tests
开发者ID:clareliguori,项目名称:regimun,代码行数:20,代码来源:login.py

示例5: find_tests_and_apps

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [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

示例6: initTest

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def initTest(klass, gn2_url, es_url):
    loader = TestLoader()
    methodNames = loader.getTestCaseNames(klass)
    return [klass(mname, gn2_url, es_url) for mname in methodNames]
开发者ID:genenetwork,项目名称:genenetwork2,代码行数:6,代码来源:test-website.py

示例7: __import__

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
         # Dynamically import test module
         module = __import__(_UNIT_TEST_PKG.format(test_name))
         test_module = getattr(module, test_name)
         # Iterate over the list of attributes for test module to find valid
         # TestCase objects.
         for name in dir(test_module):
             # Process object if subclass of TestCase.
             obj = getattr(test_module, name)
             if isinstance(obj, type) and issubclass(obj, TestCase):
                 # Check if object is subclass tests.utils.TestCase to pass
                 # required arguments.
                 use_args = True \
                     if issubclass(obj, unit_tests.utils.GadgetsTestCase) \
                     else False
                 # Get test names (methods).
                 testnames = testloader.getTestCaseNames(obj)
                 for testname in testnames:
                     if use_args:
                         # Add test with specific arguments.
                         test_instance = obj(testname, options=test_options)
                         suite.addTest(test_instance)
                         # Store max number of servers required by test.
                         num_servers = test_instance.num_servers_required
                         if num_servers > num_srv_needed:
                             num_srv_needed = num_servers
                     else:
                         # Add test without arguments (default).
                         suite.addTest(obj(testname))
 except Exception as err:  # pylint: disable=W0703
     sys.stderr.write("ERROR: Could not load tests to run: {0}"
                      "\n".format(err))
开发者ID:mysql,项目名称:mysql-shell,代码行数:33,代码来源:unittests.py

示例8: __init__

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
	def __init__(self, test_case_class):
		my_load = TestLoader()
		self.methods = my_load.getTestCaseNames(test_case_class)
开发者ID:JulienBalestra,项目名称:libft,代码行数:5,代码来源:utils_config.py


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