本文整理匯總了Python中unittest.case.TestCase方法的典型用法代碼示例。如果您正苦於以下問題:Python case.TestCase方法的具體用法?Python case.TestCase怎麽用?Python case.TestCase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類unittest.case
的用法示例。
在下文中一共展示了case.TestCase方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: addSuccess
# 需要導入模塊: from unittest import case [as 別名]
# 或者: from unittest.case import TestCase [as 別名]
def addSuccess(self, test: TestCase):
super().addSuccess(test)
self.stream.writeln('## Ending Test ##')
self.passed.append((test, ''))
logger = getLogger('djongo')
logger.setLevel(INFO)
示例2: test_retry_without_arg
# 需要導入模塊: from unittest import case [as 別名]
# 或者: from unittest.case import TestCase [as 別名]
def test_retry_without_arg(self):
# Check docstrings of decorated functions.
def func(*args):
"""func docstring"""
return 1
def func_raises(exc=Exception):
"""func_raises docstring"""
raise exc
self.assertEqual(retry(func).__doc__, func.__doc__)
self.assertEqual(retry()(func).__doc__, func.__doc__)
self.assertEqual(retry(func_raises).__doc__, func_raises.__doc__)
self.assertEqual(retry()(func_raises).__doc__, func_raises.__doc__)
# Check func returns correctly after it is decorated.
self.assertEqual(retry(func)(), 1)
self.assertEqual(retry()(func)(), 1)
# Check func raises correctly after it is decorated.
with self.assertRaises(Exception):
retry(func_raises, wait=0)()
with self.assertRaises(Exception):
retry(wait=0)(func_raises)()
with self.assertRaises(NotImplementedError):
retry(func_raises, wait=0)(NotImplementedError)
with self.assertRaises(NotImplementedError):
retry(wait=0)(func_raises)(NotImplementedError)
with self.assertRaises(NotImplementedError):
retry(func_raises, wait=0, max_attempts=0)(NotImplementedError)
with self.assertRaises(NotImplementedError):
retry(wait=0, max_attempts=0)(func_raises)(NotImplementedError)
# Check TypeError is raised if args have incorrect values.
with self.assertRaises(TypeError):
retry(max_attempts="") # needs to be an int
with self.assertRaises(TypeError):
retry(exc=TestCase) # need to be subclass of Exception (single value)
with self.assertRaises(TypeError):
retry(exc=(TestCase,)) # need to be subclass of Exception (tuple)
with self.assertRaises(TypeError):
retry(wait="") # needs to be a float