def test_catch_string(self):
# Catching a string should trigger a DeprecationWarning.
with warnings.catch_warnings():
warnings.resetwarnings()
warnings.filterwarnings("error")
str_exc = "spam"
with self.assertRaises(DeprecationWarning):
try:
raise StandardError
except str_exc:
pass
# Make sure that even if the string exception is listed in a tuple
# that a warning is raised.
with self.assertRaises(DeprecationWarning):
try:
raise StandardError
except (AssertionError, str_exc):
pass
评论列表
文章目录