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


Python unittest.TextTestRunner类代码示例

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


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

示例1: all

def all():
    '''
    This runs all tests and examples.  It is something of a compromise - seems
    to be the best solution that's independent of other libraries, doesn't
    use the file system (since code may be in a zip file), and keeps the
    number of required imports to a minimum.
    '''
    basicConfig(level=ERROR)
    log = getLogger('lepl._test.all.all')
    suite = TestSuite()
    loader = TestLoader()
    runner = TextTestRunner(verbosity=4)
    for module in ls_modules(lepl, MODULES):
        log.debug(module.__name__)
        suite.addTest(loader.loadTestsFromModule(module))
    result = runner.run(suite)
    print('\n\n\n----------------------------------------------------------'
          '------------\n')
    if version[0] == '2':
        print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} '
              .format(len(result.failures), len(result.errors)))
        assert 2 <= len(result.failures) <= 5, len(result.failures)
        assert 1 <= len(result.errors) <= 2, len(result.errors)
        target = TOTAL - NOT_DISTRIBUTED - NOT_3
    else:
        print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
              .format(len(result.failures), len(result.errors)))
        assert 0 <= len(result.failures) <= 1, len(result.failures)
        assert 0 <= len(result.errors) <= 0, len(result.errors)
        target = TOTAL - NOT_DISTRIBUTED
    print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
    assert result.testsRun == target, result.testsRun
    print('\nLooks OK to me!\n\n')
开发者ID:gcarothers,项目名称:lepl,代码行数:33,代码来源:__init__.py

示例2: __init__

 def __init__(self, output='.', stream=sys.stderr, descriptions=True, \
     verbose=False, elapsed_times=True):
     "Create a new instance of XMLTestRunner."
     verbosity = (1, 2)[verbose]
     TextTestRunner.__init__(self, stream, descriptions, verbosity)
     self.output = output
     self.elapsed_times = elapsed_times
开发者ID:garsue,项目名称:unittest-xml-reporting,代码行数:7,代码来源:__init__.py

示例3: main

def main() -> None:
    u"""Главная функция.

    :return: list набор выполненных тестов
    """
    test_runner, ssh = TextTestRunner(), SSHClient()
    result = test_runner.run(test_suites.connection_suite(ssh))
开发者ID:gitter-badger,项目名称:CLI-1,代码行数:7,代码来源:test.py

示例4: run

    def run(self):
        '''
        Finds all the tests modules in tests/, and runs them, exiting after they are all done
        '''
        from tests.server import TestServer
        from tests.test_core import WebserviceTest

        log.set_verbosity(self.verbose)
        if self.verbose >= 2:
            self.announce('Setting log level to DEBUG ({0})'.format(logging.DEBUG), level = 2)
            logging.basicConfig(level = logging.DEBUG)

        testfiles = [ ]
        if self.testmodule is None:
            for t in glob(pjoin(self._dir, 'tests', self.test_prefix + '*.py')):
                if not t.endswith('__init__.py'):
                    testfiles.append('.'.join(['tests', splitext(basename(t))[0]]))
        else:
            testfiles.append(self.testmodule)

        server = TestServer(daemonise = True, silent = (self.verbose < 3))
        server.start()
        WebserviceTest.TEST_PORT = server.port

        self.announce("Waiting for test server to start on port " + str(server.port), level=2)
        time.sleep(1)

        self.announce("Test files:" + str(testfiles), level=2)
        tests = TestLoader().loadTestsFromNames(testfiles)
        t = TextTestRunner(verbosity = self.verbose)
        result = t.run(tests)
        failed, errored = map(len, (result.failures, result.errors))
        exit(failed + errored)
开发者ID:intermine,项目名称:intermine-ws-client.py,代码行数:33,代码来源:setup.py

示例5: run

 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,代码行数:26,代码来源:setup.py

示例6: run

    def run(self):
        try:
            # Use system 'coverage' if available
            import coverage
            use_coverage = True
        except:
            use_coverage = False

        tests = TestLoader().loadTestsFromNames(self._testfiles)
        t = TextTestRunner(verbosity=1)

        if use_coverage:
            coverage.erase()
            coverage.start()

        if hasattr(unittest, "installHandler"):
            try:
                unittest.installHandler()
            except:
                print "installHandler hack failed"

        try:
            result = t.run(tests)
        except KeyboardInterrupt:
            sys.exit(1)

        if use_coverage:
            coverage.stop()

        sys.exit(int(bool(len(result.failures) > 0 or
                          len(result.errors) > 0)))
开发者ID:tomlanyon,项目名称:python-virtinst,代码行数:31,代码来源:setup.py

示例7: run

 def run(self):
     """
     Finds all the tests modules in test/, and runs them.
     """
     exclude = [pjoin(self._dir, 'test', 'cern_sso_auth_t.py')]
     testfiles = []
     for t in glob(pjoin(self._dir, 'test', '*_t.py')):
         if  not t.endswith('__init__.py') and t not in exclude:
             testfiles.append('.'.join(
                 ['test', splitext(basename(t))[0]])
             )
     testfiles.sort()
     try:
         tests = TestLoader().loadTestsFromNames(testfiles)
     except Exception as exc:
         print("\nFail to load unit tests", testfiles)
         # check which tests are failing to get imported
         for test in testfiles:
             try:
                 print("trying to import:",  test)
                 __import__(test)
             except Exception as import_err:
                 print("failed importing: ", test, import_err)
         print(exc)
         raise exc
     t = TextTestRunner(verbosity = 2)
     result = t.run(tests)
     # return a non-zero exit status on failure -- useful in CI
     if not result.wasSuccessful():
         sys.exit(1)
开发者ID:dmwm,项目名称:DAS,代码行数:30,代码来源:setup.py

示例8: run

    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,代码行数:34,代码来源:setup.py

示例9: run

    def run(self):
        '''
        Finds all the tests modules in tests/, and runs them.
        '''
        if self.coverage:
                cov = TestCoverage()
                cov.start()

        testfiles = [ ]
        for t in glob(pjoin(self._dir, 'tests', '*.py')):
            if not t.endswith('__init__.py'):
                testfiles.append('.'.join(
                    ['tests', splitext(basename(t))[0]])
                )

        tests = TestLoader().loadTestsFromNames(testfiles)
        t = TextTestRunner(verbosity = 1)
        ts = t.run(tests)

        if self.coverage:
                cov.stop()
                cov.report()

        if not ts.wasSuccessful():
		sys.exit(1)
开发者ID:frogbywyplay,项目名称:genbox_xov,代码行数:25,代码来源:setup.py

示例10: run

    def run(self):
       '''
       Finds all the tests modules in tests/, and runs them, exiting after they are all done
       '''
       from tests.testserver import TestServer
       from tests.test import WebserviceTest

       log.set_verbosity(self.verbose)

       server = TestServer()
       server.start()
       WebserviceTest.TEST_PORT = server.port

       self.announce("Waiting for test server to start on port " + str(server.port), level=2)
       time.sleep(1)

       testfiles = [ ]
       for t in glob(pjoin(self._dir, 'tests', self.test_prefix + '*.py')):
           if not t.endswith('__init__.py'):
               testfiles.append('.'.join(
                   ['tests', splitext(basename(t))[0]])
               )

       self.announce("Test files:" + str(testfiles), level=2)
       tests = TestLoader().loadTestsFromNames(testfiles)
       t = TextTestRunner(verbosity = self.verbose)
       t.run(tests)
       exit()
开发者ID:kkarra,项目名称:intermine-ws-client.py,代码行数:28,代码来源:setup.py

示例11: run

 def run(self):
     """
     Finds and executes unit tests in the 'tests' subdir.
     Because TestLoader imports the tests as a module this method
     automatically creates/updates the 'tests/__init__.py' to
     import all python scripts in the 'tests' subdir.
     """
     self.run_command('build')
     sys.path.insert(0,os.path.join(os.getcwd(),"build","lib"))
     self.tests  = []
     # make sure the 'tests' subdir actually exists.
     if not os.path.isdir(self.tests_dir):
         print "ExecuteTests: <Error> 'tests' subdir not found!"
     else:
         self.find_tests()
         self.gen_tests_init()
         # create a test suite.
         tests = TestLoader().loadTestsFromNames([t[0] for t in self.tests])
         if not self.filter is None:
             tests = self.filter_tests(tests)
         # run the test suite if it actually contains test cases.
         run_verbosity = 2
         if self.verbose == 0:
             run_verbosity = 0
         if tests.countTestCases() > 0:
             runner = TextTestRunner(verbosity=run_verbosity)
             runner.run(tests)
         else:
             print "ExecuteTests: <Warning> No test cases found!"
     sys.path.pop(0)
开发者ID:ahota,项目名称:visit_intel,代码行数:30,代码来源:setup_tests.py

示例12: run

 def run(self):
     sys.path.insert(0, os.path.join(root_dir, package_dir))
     sys.path.insert(0, os.path.join(root_dir, test_dir))
     os.chdir(test_dir)
     import all_tests
     t = TextTestRunner(verbosity=2)
     t.run(all_tests.suite())
开发者ID:mosaic-data-model,项目名称:mosaic-python,代码行数:7,代码来源:setup.py

示例13: run

 def run(self):
     sys.path.insert(0, os.path.join(self._dir, BOKEEP_SRC_DIR) )
     sys.path.insert(0, os.path.join(self._dir, 'tests') )
     tests = list(self.generate_test_files())
     tests = TestLoader().loadTestsFromNames( tests )
     t = TextTestRunner(verbosity = 1)
     t.run(tests)
开发者ID:paritworkercoop,项目名称:bokeep-mirror,代码行数:7,代码来源:setup.py

示例14: main

def main():
    my_dir = os.path.dirname(os.path.abspath(__file__))
    sys.path.insert(0, os.path.abspath(os.path.join(my_dir, '..')))
    has_pep8 = False
    try:
        import pep8
        has_pep8 = True
    except ImportError:
        if '--with-pep8' in sys.argv[1:]:
            sys.stderr.write('# Could not find pep8 library.')
            sys.exit(1)

    if has_pep8:
        guide = pep8.StyleGuide(
            ignore=[],
            paths=['wtforms/'],
            exclude=['wtforms/ext/sqlalchemy', 'wtforms/ext/appengine'],
            max_line_length=130,
        )
        report = guide.check_files()
        if report.total_errors:
            sys.exit(1)

    extra_tests = tuple(x for x in sys.argv[1:] if '-' not in x)
    suite = make_suite('', extra_tests)

    runner = TextTestRunner(verbosity=(sys.argv.count('-v') - sys.argv.count('-q') + 1))
    result = runner.run(suite)
    sys.exit(not result.wasSuccessful())
开发者ID:andymccurdy,项目名称:wtforms,代码行数:29,代码来源:runtests.py

示例15: _run_tests

    def _run_tests(self):
        secrets_current = pjoin(self._dir, 'rtwo/test', 'secrets.py')
        secrets_dist = pjoin(self._dir, 'rtwo/test', 'secrets.py.dist')

        if not os.path.isfile(secrets_current):
            print("Missing " + secrets_current)
            print("Maybe you forgot to copy it from .dist:")
            print("cp rtwo/test/secrets.py.dist rtwo/test/secrets.py")
            sys.exit(1)

        mtime_current = os.path.getmtime(secrets_current)
        mtime_dist = os.path.getmtime(secrets_dist)

        if mtime_dist > mtime_current:
            print("It looks like test/secrets.py file is out of date.")
            print("Please copy the new secrets.py.dist file over otherwise" +
                  " tests might fail")

        testfiles = []
        for test_path in TEST_PATHS:
            for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
                testfiles.append('.'.join(
                    [test_path.replace('/', '.'), splitext(basename(t))[0]]))
        tests = TestLoader().loadTestsFromNames(testfiles)

        t = TextTestRunner(verbosity=2)
        res = t.run(tests)
        return not res.wasSuccessful()
开发者ID:cdosborn,项目名称:rtwo,代码行数:28,代码来源:setup.py


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