當前位置: 首頁>>代碼示例>>Python>>正文


Python unittest.TextTestRunner方法代碼示例

本文整理匯總了Python中unittest.TextTestRunner方法的典型用法代碼示例。如果您正苦於以下問題:Python unittest.TextTestRunner方法的具體用法?Python unittest.TextTestRunner怎麽用?Python unittest.TextTestRunner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在unittest的用法示例。


在下文中一共展示了unittest.TextTestRunner方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_tests

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def run_tests(test_to_run, config=None):
    global CONFIG, STORAGE_CONFIG, STORAGE

    CONFIG = json.load(args.config) if config else default_config()
    STORAGE_CONFIG = extract_storage_config(CONFIG)
    STORAGE = InternalStorage(STORAGE_CONFIG).storage_handler

    suite = unittest.TestSuite()
    if test_to_run == 'all':
        suite.addTest(unittest.makeSuite(TestPywren))
    else:
        try:
            suite.addTest(TestPywren(test_to_run))
        except ValueError:
            print("unknown test, use: --help")
            sys.exit()

    runner = unittest.TextTestRunner()
    runner.run(suite) 
開發者ID:pywren,項目名稱:pywren-ibm-cloud,代碼行數:21,代碼來源:tests.py

示例2: testRunnerRegistersResult

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def testRunnerRegistersResult(self):
        class Test(unittest.TestCase):
            def testFoo(self):
                pass
        originalRegisterResult = unittest.runner.registerResult
        def cleanup():
            unittest.runner.registerResult = originalRegisterResult
        self.addCleanup(cleanup)

        result = unittest.TestResult()
        runner = unittest.TextTestRunner(stream=io.StringIO())
        # Use our result object
        runner._makeResult = lambda: result

        self.wasRegistered = 0
        def fakeRegisterResult(thisResult):
            self.wasRegistered += 1
            self.assertEqual(thisResult, result)
        unittest.runner.registerResult = fakeRegisterResult

        runner.run(unittest.TestSuite())
        self.assertEqual(self.wasRegistered, 1) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:24,代碼來源:test_runner.py

示例3: test_startTestRun_stopTestRun_called

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def test_startTestRun_stopTestRun_called(self):
        class LoggingTextResult(LoggingResult):
            separator2 = ''
            def printErrors(self):
                pass

        class LoggingRunner(unittest.TextTestRunner):
            def __init__(self, events):
                super(LoggingRunner, self).__init__(io.StringIO())
                self._events = events

            def _makeResult(self):
                return LoggingTextResult(self._events)

        events = []
        runner = LoggingRunner(events)
        runner.run(unittest.TestSuite())
        expected = ['startTestRun', 'stopTestRun']
        self.assertEqual(events, expected) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:21,代碼來源:test_runner.py

示例4: _run_suite

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def _run_suite(suite):
    """Run tests from a unittest.TestSuite-derived class."""
    if verbose:
        runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
                                         failfast=failfast)
    else:
        runner = BasicTestRunner()

    result = runner.run(suite)
    if not result.wasSuccessful():
        if len(result.errors) == 1 and not result.failures:
            err = result.errors[0][1]
        elif len(result.failures) == 1 and not result.errors:
            err = result.failures[0][1]
        else:
            err = "multiple errors occurred"
            if not verbose: err += "; run in verbose mode for details"
        raise TestFailed(err) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:20,代碼來源:support.py

示例5: _render_plain

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def _render_plain(self, package_name, test_name):
        self.response.headers["Content-Type"] = "text/plain"
        runner = unittest.TextTestRunner(self.response.out)
        suite, error = _create_suite(package_name, test_name, _LOCAL_TEST_DIR)
        if not error:
            self.response.out.write("====================\n" \
                                    "GAEUnit Test Results\n" \
                                    "====================\n\n")
            _run_test_suite(runner, suite)
        else:
            self.error(404)
            self.response.out.write(error)


##############################################################################
# JSON test classes
############################################################################## 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:19,代碼來源:gaeunit.py

示例6: main

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def main(sdk_path, test_path, test_pattern):
  # If the SDK path points to a Google Cloud SDK installation
  # then we should alter it to point to the GAE platform location.
  if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')):
    sdk_path = os.path.join(sdk_path, 'platform/google_appengine')

  # Make sure google.appengine.* modules are importable.
  fixup_paths(sdk_path)

  # Make sure all bundled third-party packages are available.
  import dev_appserver
  dev_appserver.fix_sys_path()

  # Loading appengine_config from the current project ensures that any
  # changes to configuration there are available to all tests (e.g.
  # sys.path modifications, namespaces, etc.)
  try:
    import appengine_config
    (appengine_config)
  except ImportError:
    print('Note: unable to import appengine_config.')

  # Discover and run tests.
  suite = unittest.loader.TestLoader().discover(test_path, test_pattern)
  return unittest.TextTestRunner(verbosity=2).run(suite) 
開發者ID:lipis,項目名稱:github-stats,代碼行數:27,代碼來源:runner.py

示例7: run

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [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

示例8: main

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def main():
    """Runs the suite of unit tests"""

    # Do the tests
    suite = unittest.TestSuite()
    suite.addTests(unittest.makeSuite(TestXnos))
    suite.addTests(unittest.makeSuite(TestPandocAttributes))
    result = unittest.TextTestRunner(verbosity=1).run(suite)
    n_errors = len(result.errors)
    n_failures = len(result.failures)

    if n_errors or n_failures:
        print('\n\nSummary: %d errors and %d failures reported\n'%\
            (n_errors, n_failures))

    print()

    sys.exit(n_errors+n_failures) 
開發者ID:tomduck,項目名稱:pandoc-xnos,代碼行數:20,代碼來源:test.py

示例9: test

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests) 
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:7,代碼來源:server.py

示例10: run

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def run(self):
    suite = unittest.defaultTestLoader.discover('.', pattern='*_test.py')
    unittest.TextTestRunner().run(suite) 
開發者ID:google,項目名稱:macops,代碼行數:5,代碼來源:setup.py

示例11: main

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def main():
    """Main function to run as shell script."""
    loader = unittest.TestLoader()
    suite = loader.discover(path.abspath(path.dirname(__file__)), pattern='test_*.py')
    runner = unittest.TextTestRunner(buffer=True)
    runner.run(suite) 
開發者ID:frost-nzcr4,項目名稱:find_forks,代碼行數:8,代碼來源:run.py

示例12: run_tests

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def run_tests(self):
        test_suite = unittest.TestLoader().discover('.', pattern='test*.py')
        result = unittest.TextTestRunner(buffer=True).run(test_suite)
        sys.exit(not result.wasSuccessful()) 
開發者ID:chaoss,項目名稱:grimoirelab-sortinghat,代碼行數:6,代碼來源:setup.py

示例13: run_mock

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def run_mock(test_name):
    """Run a unit test from mock class

    :param test_name: test name that must be executed
    :returns: test instance
    """
    # BasicTestCase import should be inside method to avoid collecting tests error in behave with python 3.7
    from toolium.test_cases import BasicTestCase

    class MockTestClass(BasicTestCase):
        def setUp(self):
            root_path = os.path.dirname(os.path.realpath(__file__))
            self.config_files.set_config_directory(os.path.join(root_path, 'conf'))
            super(MockTestClass, self).setUp()

        def mock_pass(self):
            pass

        def mock_fail(self):
            raise AssertionError('test error')

    suite = unittest.TestSuite()
    test = MockTestClass(test_name)
    suite.addTest(test)
    unittest.TextTestRunner().run(suite)
    return test 
開發者ID:Telefonica,項目名稱:toolium,代碼行數:28,代碼來源:test_test_cases.py

示例14: main

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def main():
    unittest.main(defaultTest='suite',
                  testRunner=unittest.TextTestRunner(verbosity=2)) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:5,代碼來源:test_all.py

示例15: test_init

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def test_init(self):
        runner = unittest.TextTestRunner()
        self.assertFalse(runner.failfast)
        self.assertFalse(runner.buffer)
        self.assertEqual(runner.verbosity, 1)
        self.assertEqual(runner.warnings, None)
        self.assertTrue(runner.descriptions)
        self.assertEqual(runner.resultclass, unittest.TextTestResult) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:test_runner.py


注:本文中的unittest.TextTestRunner方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。