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


Python TestLoader.discover方法代码示例

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


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

示例1: discover

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
def discover(root_dir):
    if not os.path.exists(root_dir):
        return []

    loader = TestLoader()
    prev_dir = os.curdir
    os.chdir(root_dir)
    
    tests = loader.discover(root_dir, top_level_dir=root_dir)
    os.chdir(prev_dir)
    
    ret = []
    for suite in tests:
        for suite2 in suite:
            if suite2.__class__.__name__ == 'ModuleImportFailure':
                continue
            for test in suite2:
                name = ".".join((test.__class__.__name__, test._testMethodName))
                module = test.__module__
                ret.append([symbol(":name"), name,
                            symbol(":module"), module,
                            symbol(":root"), root_dir])

    modkey = lambda x: x[3]
    ret.sort(key=modkey)

    return [[k, list(g)] for k,g in groupby(ret, key=modkey)] # Converting to a list of lists
开发者ID:Abuelodelanada,项目名称:emacs-config,代码行数:29,代码来源:epy-unittest.py

示例2: run

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
 def run(self):
     where = os.path.join('pythran', 'tests')
     try:
         import py
         import xdist
         import multiprocessing
         cpu_count = multiprocessing.cpu_count()
         args = ["-n", str(cpu_count), where]
         if self.failfast:
             args.insert(0, '-x')
         if self.cov:
             try:
                 import pytest_cov
                 args = ["--cov-report", "html",
                         "--cov-report", "annotate",
                         "--cov", "pythran"] + args
             except ImportError:
                 print ("W: Skipping coverage analysis, pytest_cov"
                         "not found")
         py.test.cmdline.main(args)
     except ImportError:
         print ("W: Using only one thread, "
                 "try to install pytest-xdist package")
         loader = TestLoader()
         t = TextTestRunner(failfast=self.failfast)
         t.run(loader.discover(where))
开发者ID:franckCJ,项目名称:pythran,代码行数:28,代码来源:setup.py

示例3: run

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
    def run(self):
        # Do not include current directory, validate using installed pythran
        current_dir = _exclude_current_dir_from_import()
        os.chdir("pythran/tests")
        where = os.path.join(current_dir, 'pythran')

        from pythran import test_compile
        test_compile()

        try:
            import py
            import xdist
            args = ["-n", str(self.num_threads), where, '--pep8']
            if self.failfast:
                args.insert(0, '-x')
            if self.cov:
                try:
                    import pytest_cov
                    args = ["--cov-report", "html",
                            "--cov-report", "annotate",
                            "--cov", "pythran"] + args
                except ImportError:
                    print ("W: Skipping coverage analysis, pytest_cov"
                           "not found")
            if py.test.cmdline.main(args) == 0:
                print "\\_o<"
        except ImportError:
            print ("W: Using only one thread, "
                   "try to install pytest-xdist package")
            loader = TestLoader()
            t = TextTestRunner(failfast=self.failfast)
            t.run(loader.discover(where))
            if t.wasSuccessful():
                print "\\_o<"
开发者ID:baoboa,项目名称:pythran,代码行数:36,代码来源:setup.py

示例4: discover

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
def discover(directory):
    directory = os.path.expanduser(directory) # The tilde does not work with os.chdir
    os.chdir(directory)
    
    # Discovering tests using unittest framework
    loader = TestLoader()
    tests = loader.discover(directory, top_level_dir=directory)
    result = EmacsTestResult()
    
    # Create a buffer (if it not exists) and put the formatted results
    # inside it
    let = Let()
    lisp.get_buffer_create("unittest")
    let.push_excursion()
    lisp.set_buffer("unittest")
    lisp.erase_buffer()
    tests.run(result)
    lisp.insert("\n")
    lisp.insert("Errors:\n")
    for test, traceback in result.errors:
        lisp.insert(str(test))
        lisp.insert(traceback)
    let.pop_excursion()
    
    lisp.pop_to_buffer("unittest")
    lisp.compilation_mode()
    lisp.beginning_of_buffer()
开发者ID:pdee,项目名称:pdee,代码行数:29,代码来源:unitdiscover.py

示例5: load_tests

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
def load_tests():
    test_suite = TestSuite()
    this_dir = os.path.dirname(__file__)
    loader = TestLoader()
    package_tests = loader.discover(start_dir=this_dir)
    test_suite.addTests(package_tests)
    return test_suite
开发者ID:ricequant,项目名称:rqalpha,代码行数:9,代码来源:__init__.py

示例6: run

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
 def run(self, ):
     loader = TestLoader()
     tests = loader.discover('.', 'test_*.py')
     t = XMLTestRunner(verbosity=1, output=self.TEST_RESULTS)
     res = t.run(tests)
     if not res.wasSuccessful():
         raise FailTestException()
开发者ID:laslabs,项目名称:Python-Carepoint,代码行数:9,代码来源:tests.py

示例7: run

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
 def run(self):
     import os
     from unittest import TestLoader, TextTestRunner
     cur_dir = os.path.dirname(os.path.abspath(__file__))
     loader = TestLoader()
     test_suite = loader.discover(cur_dir)
     runner = TextTestRunner(verbosity=2)
     runner.run(test_suite)
开发者ID:chrisgeo,项目名称:serviceapi,代码行数:10,代码来源:manage.py

示例8: allTests

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
def allTests():
    """Retrieve a test suite containing all tests."""
    # Explicitly load all tests by name and not using a single discovery
    # to be able to easily deselect parts.
    tests = ["testInvocationLogger.py"]

    loader = TestLoader()
    directory = dirname(__file__)
    suites = [loader.discover(directory, pattern=test) for test in tests]
    return TestSuite(suites)
开发者ID:d-e-s-o,项目名称:logger,代码行数:12,代码来源:__init__.py

示例9: TestSuiteDesigner

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
class TestSuiteDesigner(object):
    def __init__(self, agility):
        self._agility = agility
        self._testloader = TestLoader()
        
    def discover(self, startpath='', pattern='test*.py', rootpath=None):
        startpath = startpath or os.path.join(agility.cfg.path.pluginsdir, 'fieldtests', 'testcases')
        startpath = os.path.realpath(os.path.abspath(startpath))
        if rootpath: pythonpath.addPath(rootpath)
        logger.info('Discovering test cases in path [%s], root path [%s]', startpath, rootpath or '')
        suite = self._testloader.discover(startpath, pattern=pattern, top_level_dir=rootpath)
        return suite
开发者ID:crgerber,项目名称:csc-agility-python-shell,代码行数:14,代码来源:testdesigner.py

示例10: available_points

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
    def available_points(self):
        testLoader = TestLoader()
        tests = testLoader.discover('.', 'test*.py', None)
        tests = list(chain(*chain(*tests._tests)))

        points = map(_parse_points, tests)
        names = map(_name_test, tests)

        result = dict(zip(names, points))

        with open('.available_points.json', 'w') as f:
            json.dump(result, f, ensure_ascii=False)
开发者ID:matnel,项目名称:hy-css-dataextraction,代码行数:14,代码来源:runner.py

示例11: run_unittests

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
def run_unittests(do_coverage=True):
    loader = TestLoader()
    if do_coverage:
        cov = coverage.coverage(source=["coinpy"], branch=True)
        cov.start()
    suite = loader.discover("unit", pattern='test_*.py')
    
    runner = unittest.TextTestRunner()
    runner.run(suite)
    if do_coverage:
        
        cov.stop()
        cov.save()
        cov.html_report(directory="coverage_html")
开发者ID:sirk390,项目名称:coinpy,代码行数:16,代码来源:run_tests.py

示例12: run

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
 def run(self):
     where = os.path.join('pythran', 'tests')
     try:
         import py
         import xdist
         import multiprocessing
         cpu_count = multiprocessing.cpu_count()
         args = ["-n", str(cpu_count), where]
         if self.failfast:
             args.insert(0, '-x')
         py.test.cmdline.main(args)
     except ImportError:
         print ("W: Using only one thread, "
                 "try to install pytest-xdist package")
         loader = TestLoader()
         t = TextTestRunner()
         t.run(loader.discover(where))
开发者ID:Midhrin,项目名称:pythran,代码行数:19,代码来源:setup.py

示例13: allTests

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
def allTests():
  """Retrieve a test suite containing all tests."""
  from os.path import (
    dirname,
  )
  from unittest import (
    TestLoader,
    TestSuite,
  )

  # Explicitly load all tests by name and not using a single discovery
  # to be able to easily deselect parts.
  tests = [
    "testDefer.py",
  ]

  loader = TestLoader()
  directory = dirname(__file__)
  suites = [loader.discover(directory, pattern=test) for test in tests]
  return TestSuite(suites)
开发者ID:d-e-s-o,项目名称:cleanup,代码行数:22,代码来源:__init__.py

示例14: run

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

        # Perform imports in run to avoid test dependencies in setup
        from xmlrunner import XMLTestRunner
        import coverage
        from unittest import TestLoader

        loader = TestLoader()
        tests = loader.discover('.', 'test_*.py')
        t = XMLTestRunner(verbosity=1, output=self.TEST_RESULTS)

        cov = coverage.Coverage(
            omit=['*/tests/', 'test_*.py', ],
            source=self.MODULE_NAMES,
        )
        cov.start()
        t.run(tests)
        cov.stop()
        cov.save()
        cov.xml_report(outfile=self.COVERAGE_RESULTS)
开发者ID:LiberTang0,项目名称:Python-Carepoint,代码行数:22,代码来源:tests.py

示例15: TestSuite

# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import discover [as 别名]
    sys.path[0] = testdir
else:
    sys.path.insert(0, testdir)

from support import TestCase, MemoryTest, PerformanceTest

suite = TestSuite()

for name in args.suite:
    TestCase.setup_loader()
    if name == 'unit':
        pattern = 'test_*.py'
    elif name == 'performance':
        pattern = 'perf_*.py'
        PerformanceTest.setup_loader()
        PerformanceTest.start_new_results()
    elif name == 'memory':
        pattern = 'mem_*.py'
        MemoryTest.setup_loader()
        MemoryTest.start_new_results()
    elif name == 'documentation':
        pattern = 'documentation.py'
    loader = TestLoader()
    tests = loader.discover('.', pattern)
    suite.addTest(tests)

runner = TextTestRunner(verbosity=args.verbose, buffer=args.buffer, failfast=args.failfast)
result = runner.run(suite)
if result.errors or result.failures:
    sys.exit(1)
开发者ID:geertj,项目名称:pyskiplist,代码行数:32,代码来源:runtests.py


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