本文整理汇总了Python中unittest2.TextTestRunner方法的典型用法代码示例。如果您正苦于以下问题:Python unittest2.TextTestRunner方法的具体用法?Python unittest2.TextTestRunner怎么用?Python unittest2.TextTestRunner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest2
的用法示例。
在下文中一共展示了unittest2.TextTestRunner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_suite
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 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)
示例2: main
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def main(sdk_path, test_path, third_party_path=None):
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
if third_party_path:
sys.path.insert(0, third_party_path)
try:
import appengine_config
(appengine_config)
except ImportError:
print "Note: unable to import appengine_config."
suite = unittest2.loader.TestLoader().discover(test_path,
pattern='*_test.py')
result = unittest2.TextTestRunner(verbosity=2).run(suite)
if len(result.errors) > 0 or len(result.failures) > 0:
sys.exit(1)
示例3: run
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 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)
示例4: testRunnerRegistersResult
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def testRunnerRegistersResult(self):
class Test(unittest2.TestCase):
def testFoo(self):
pass
originalRegisterResult = unittest2.runner.registerResult
def cleanup():
unittest2.runner.registerResult = originalRegisterResult
self.addCleanup(cleanup)
result = unittest2.TestResult()
runner = unittest2.TextTestRunner(stream=StringIO())
# Use our result object
runner._makeResult = lambda: result
self.wasRegistered = 0
def fakeRegisterResult(thisResult):
self.wasRegistered += 1
self.assertEqual(thisResult, result)
unittest2.runner.registerResult = fakeRegisterResult
runner.run(unittest2.TestSuite())
self.assertEqual(self.wasRegistered, 1)
示例5: test_startTestRun_stopTestRun_called
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def test_startTestRun_stopTestRun_called(self):
class LoggingTextResult(LoggingResult):
separator2 = ''
def printErrors(self):
pass
class LoggingRunner(unittest2.TextTestRunner):
def __init__(self, events):
super(LoggingRunner, self).__init__(StringIO())
self._events = events
def _makeResult(self):
return LoggingTextResult(self._events)
events = []
runner = LoggingRunner(events)
runner.run(unittest2.TestSuite())
expected = ['startTestRun', 'stopTestRun']
self.assertEqual(events, expected)
示例6: _run_unittests
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def _run_unittests(): # type: () -> list(str)
try:
import unittest2 as unittest
except ImportError:
import unittest
tests = unittest.TestLoader().discover('unittests')
test_result = unittest.TextTestRunner(
stream=sys.stdout,
verbosity=2,
).run(tests)
problems = test_result.errors + test_result.failures
return [str(problem[0]) for problem in problems]
示例7: run
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [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()
示例8: main
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def main(args=None):
unittest_dir = '.'
unittest_suite = unittest.defaultTestLoader.discover(unittest_dir)
kwargs = {}
if args and '-v' in args:
kwargs['verbosity'] = 2
runner = unittest.TextTestRunner(sys.stdout, "Unittests",
**kwargs)
results = runner.run(unittest_suite)
return results.wasSuccessful()
示例9: main
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def main(argv):
args = _ParseArgs(argv)
suite = unittest2.loader.TestLoader().discover(
start_dir=os.path.join(os.path.dirname(__file__), 'tests'),
pattern='*_test.py')
# 1: Does not show individual test names.
# 2: Shows individual test names.
show_test_names = 2 if args.verbose else 1
unittest2.TextTestRunner(verbosity=show_test_names).run(suite)
示例10: run
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def run(self):
if(sys.stdout.encoding == 'utf-8'):
print('╭─────────────────────────────────────╮')
print('│ │')
print('│ Test Start │')
print('│ │')
print('╰─────────────────────────────────────╯')
else:
print('Test Start')
import tests
testSuite = unittest.TestSuite(tests.testsuite())
runner = unittest.TextTestRunner(verbosity=2)
results = runner.run(testSuite)
sys.exit(0 if results.wasSuccessful() else 1)
pass
示例11: test_init
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def test_init(self):
runner = unittest2.TextTestRunner()
self.assertFalse(runner.failfast)
self.assertFalse(runner.buffer)
self.assertEqual(runner.verbosity, 1)
self.assertTrue(runner.descriptions)
self.assertEqual(runner.resultclass, unittest2.TextTestResult)
示例12: testBufferAndFailfast
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def testBufferAndFailfast(self):
class Test(unittest2.TestCase):
def testFoo(self):
pass
result = unittest2.TestResult()
runner = unittest2.TextTestRunner(stream=StringIO(), failfast=True,
buffer=True)
# Use our result object
runner._makeResult = lambda: result
runner.run(Test('testFoo'))
self.assertTrue(result.failfast)
self.assertTrue(result.buffer)
示例13: test_works_with_result_without_startTestRun_stopTestRun
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def test_works_with_result_without_startTestRun_stopTestRun(self):
class OldTextResult(OldTestResult):
def __init__(self, *_):
super(OldTextResult, self).__init__()
separator2 = ''
def printErrors(self):
pass
runner = unittest2.TextTestRunner(stream=StringIO(),
resultclass=OldTextResult)
runner.run(unittest2.TestSuite())
示例14: test_resultclass
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def test_resultclass(self):
def MockResultClass(*args):
return args
STREAM = object()
DESCRIPTIONS = object()
VERBOSITY = object()
runner = unittest2.TextTestRunner(STREAM, DESCRIPTIONS, VERBOSITY,
resultclass=MockResultClass)
self.assertEqual(runner.resultclass, MockResultClass)
expectedresult = (runner.stream, DESCRIPTIONS, VERBOSITY)
self.assertEqual(runner._makeResult(), expectedresult)
示例15: test_oldresult
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TextTestRunner [as 别名]
def test_oldresult(self):
class Test(unittest2.TestCase):
def testFoo(self):
pass
runner = unittest2.TextTestRunner(resultclass=OldTestResult,
stream=StringIO())
# This will raise an exception if TextTestRunner can't handle old
# test result objects
runner.run(Test('testFoo'))