本文整理匯總了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)
示例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)
示例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)
示例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)
示例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
##############################################################################
示例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)
示例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)
示例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)
示例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)
示例10: run
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def run(self):
suite = unittest.defaultTestLoader.discover('.', pattern='*_test.py')
unittest.TextTestRunner().run(suite)
示例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)
示例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())
示例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
示例14: main
# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import TextTestRunner [as 別名]
def main():
unittest.main(defaultTest='suite',
testRunner=unittest.TextTestRunner(verbosity=2))
示例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)