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


Python unittest.defaultTestLoader方法代码示例

本文整理汇总了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) 
开发者ID:rbarrois,项目名称:throttle,代码行数:27,代码来源:setup.py

示例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 
开发者ID:t4ngo,项目名称:dragonfly,代码行数:22,代码来源:suites.py

示例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) 
开发者ID:MartijnBraam,项目名称:python-isc-dhcp-leases,代码行数:25,代码来源:setup.py

示例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) 
开发者ID:openstack,项目名称:oslotest,代码行数:21,代码来源:test_base.py

示例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

######################################################## 
开发者ID:elsigh,项目名称:browserscope,代码行数:15,代码来源:gaeunit.py

示例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. 
开发者ID:elsigh,项目名称:browserscope,代码行数:13,代码来源:gaeunit.py

示例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) 
开发者ID:elsigh,项目名称:browserscope,代码行数:32,代码来源:gaeunit.py

示例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 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:14,代码来源:__main__.py

示例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() 
开发者ID:belson17,项目名称:modred,代码行数:7,代码来源:alltests.py

示例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) 
开发者ID:hhyo,项目名称:mybatis-mapper2sql,代码行数:9,代码来源:setup.py

示例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 
开发者ID:CERT-Polska,项目名称:n6,代码行数:7,代码来源:auth_api_with_ldap_api_replacement_quicktest.py

示例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) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:12,代码来源:discover_tests.py

示例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 
开发者ID:haddocking,项目名称:pdb-tools,代码行数:12,代码来源:__init__.py

示例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) 
开发者ID:comger,项目名称:tor_access,代码行数:10,代码来源:setup.py

示例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() 
开发者ID:jashandeep-sohi,项目名称:python-blowfish,代码行数:30,代码来源:dist.py


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