本文整理汇总了Python中unittest2.TestResult方法的典型用法代码示例。如果您正苦于以下问题:Python unittest2.TestResult方法的具体用法?Python unittest2.TestResult怎么用?Python unittest2.TestResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest2
的用法示例。
在下文中一共展示了unittest2.TestResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRunnerRegistersResult
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [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)
示例2: test_run_call_order__error_in_tearDown_default_result
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def test_run_call_order__error_in_tearDown_default_result(self):
class Foo(Test.LoggingTestCase):
def defaultTestResult(self):
return LoggingResult(self.events)
def tearDown(self):
super(Foo, self).tearDown()
raise RuntimeError('raised by Foo.tearDown')
events = []
Foo(events).run()
expected = ['startTestRun', 'startTest', 'setUp', 'test', 'tearDown',
'addError', 'stopTest', 'stopTestRun']
self.assertEqual(events, expected)
# "TestCase.run() still works when the defaultTestResult is a TestResult
# that does not support startTestRun and stopTestRun.
示例3: test_startTest
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def test_startTest(self):
class Foo(unittest2.TestCase):
def test_1(self):
pass
test = Foo('test_1')
result = unittest2.TestResult()
result.startTest(test)
self.assertTrue(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 1)
self.assertEqual(result.shouldStop, False)
result.stopTest(test)
# "Called after the test case test has been executed, regardless of
# the outcome. The default implementation does nothing."
示例4: test_startTestRun_stopTestRun
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def test_startTestRun_stopTestRun(self):
result = unittest2.TestResult()
result.startTestRun()
result.stopTestRun()
# "addSuccess(test)"
# ...
# "Called when the test case test succeeds"
# ...
# "wasSuccessful() - Returns True if all tests run so far have passed,
# otherwise returns False"
# ...
# "testsRun - The total number of tests run so far."
# ...
# "errors - A list containing 2-tuples of TestCase instances and
# formatted tracebacks. Each tuple represents a test which raised an
# unexpected exception. Contains formatted
# tracebacks instead of sys.exc_info() results."
# ...
# "failures - A list containing 2-tuples of TestCase instances and
# formatted tracebacks. Each tuple represents a test where a failure was
# explicitly signalled using the TestCase.fail*() or TestCase.assert*()
# methods. Contains formatted tracebacks instead
# of sys.exc_info() results."
示例5: testInterruptCaught
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def testInterruptCaught(self):
default_handler = signal.getsignal(signal.SIGINT)
result = unittest2.TestResult()
unittest2.installHandler()
unittest2.registerResult(result)
self.assertNotEqual(signal.getsignal(signal.SIGINT), default_handler)
def test(result):
pid = os.getpid()
os.kill(pid, signal.SIGINT)
result.breakCaught = True
self.assertTrue(result.shouldStop)
try:
test(result)
except KeyboardInterrupt:
self.fail("KeyboardInterrupt not handled")
self.assertTrue(result.breakCaught)
示例6: testSecondInterrupt
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def testSecondInterrupt(self):
result = unittest2.TestResult()
unittest2.installHandler()
unittest2.registerResult(result)
def test(result):
pid = os.getpid()
os.kill(pid, signal.SIGINT)
result.breakCaught = True
self.assertTrue(result.shouldStop)
os.kill(pid, signal.SIGINT)
self.fail("Second KeyboardInterrupt not raised")
try:
test(result)
except KeyboardInterrupt:
pass
else:
self.fail("Second KeyboardInterrupt not raised")
self.assertTrue(result.breakCaught)
示例7: testTwoResults
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def testTwoResults(self):
unittest2.installHandler()
result = unittest2.TestResult()
unittest2.registerResult(result)
new_handler = signal.getsignal(signal.SIGINT)
result2 = unittest2.TestResult()
unittest2.registerResult(result2)
self.assertEqual(signal.getsignal(signal.SIGINT), new_handler)
result3 = unittest2.TestResult()
def test(result):
pid = os.getpid()
os.kill(pid, signal.SIGINT)
try:
test(result)
except KeyboardInterrupt:
self.fail("KeyboardInterrupt not handled")
self.assertTrue(result.shouldStop)
self.assertTrue(result2.shouldStop)
self.assertFalse(result3.shouldStop)
示例8: testRemoveResult
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def testRemoveResult(self):
result = unittest2.TestResult()
unittest2.registerResult(result)
unittest2.installHandler()
self.assertTrue(unittest2.removeResult(result))
# Should this raise an error instead?
self.assertFalse(unittest2.removeResult(unittest2.TestResult()))
try:
pid = os.getpid()
os.kill(pid, signal.SIGINT)
except KeyboardInterrupt:
pass
self.assertFalse(result.shouldStop)
示例9: test_skip_doesnt_run_setup
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def test_skip_doesnt_run_setup(self):
class Foo(unittest2.TestCase):
wasSetUp = False
wasTornDown = False
def setUp(self):
Foo.wasSetUp = True
def tornDown(self):
Foo.wasTornDown = True
def test_1(self):
pass
test_1 = unittest2.skip('testing')(test_1)
result = unittest2.TestResult()
test = Foo("test_1")
suite = unittest2.TestSuite([test])
suite.run(result)
self.assertEqual(result.skipped, [(test, "testing")])
self.assertFalse(Foo.wasSetUp)
self.assertFalse(Foo.wasTornDown)
示例10: test_decorated_skip
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def test_decorated_skip(self):
def decorator(func):
def inner(*a):
return func(*a)
return inner
class Foo(unittest2.TestCase):
def test_1(self):
pass
test_1 = decorator(unittest2.skip('testing')(test_1))
result = unittest2.TestResult()
test = Foo("test_1")
suite = unittest2.TestSuite([test])
suite.run(result)
self.assertEqual(result.skipped, [(test, "testing")])
示例11: run
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def run(self, test):
result = unittest.TestResult()
test(result)
return result
示例12: testBufferAndFailfast
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [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: testInheritance
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def testInheritance(self):
self.assertIsSubclass(unittest2.TestCase, unittest.TestCase)
self.assertIsSubclass(unittest2.TestResult, unittest.TestResult)
self.assertIsSubclass(unittest2.TestSuite, unittest.TestSuite)
self.assertIsSubclass(unittest2.TextTestRunner, unittest.TextTestRunner)
self.assertIsSubclass(unittest2.TestLoader, unittest.TestLoader)
self.assertIsSubclass(unittest2.TextTestResult, unittest.TestResult)
示例14: test_countTestCases
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def test_countTestCases(self):
class Foo(unittest2.TestCase):
def test(self): pass
self.assertEqual(Foo('test').countTestCases(), 1)
# "Return the default type of test result object to be used to run this
# test. For TestCase instances, this will always be
# unittest2.TestResult; subclasses of TestCase should
# override this as necessary."
示例15: resultFactory
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestResult [as 别名]
def resultFactory(*_):
return unittest2.TestResult()