當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。