我有以下代码块
class APITests(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
self.app = app.test_client()
app.config['SECRET_KEY'] = 'kjhk'
def test_exn(self, query):
query.all.side_effect = ValueError('test')
rv = self.app.get('/exn/')
assert rv.status_code == 400
我想检查self.app.get('/exn/
)的返回代码。但是,我注意到query.all()
将异常传播到测试用例,而不是捕获它并返回错误代码。在
在Flask中抛出异常时,如何检查无效输入的返回代码?在
您可以
assertRaise
来自werkzeug
的异常。在示例:
相关问题 更多 >
编程相关推荐