我的代码是像下面除了块不捕获异常在Python
class Something(models.Model)
def exception(self)
try:
Something.objects.all()
except Exception():
raise Exception()
称为从测试用例,其工作这种方法,但我需要提高的例外,它不捕获异常 ,这里是我的测试用例
def test_exception(self):
instance = Something()
instance.exception()
其工作正常,但我需要从引发异常除了块
这是很不清楚你想要做什么。你为什么从你的catch-block中提出一个例外?另外,在你的例子中有很多的语法错误(例如''''''异常''和'异常'''')。 –
如果你使用python unittest框架,你可能想使用assertRaises(异常)方法。 – Nicoretti