擅长:python、mysql、java
<p>好吧,所以我是个白痴。不敢相信我以前没注意到。在http\u错误中有一个异常对象。在我的测试中,我在调用validate_请求之前调用了http_错误,因此我错过了它。以下是正确答案:</p>
<pre><code>from werkzeug.exceptions import HTTPException
def test_validate_request(self):
# Ensure that an invalid accept header type will return a 406
self.view.accept_header = 'foo/bar'
with self.assertRaises(HTTPException) as http_error:
self.view.validate_request()
self.assertEqual(http_error.exception.code, 406)
</code></pre>
<p>p.S.孩子们,当你累得要死的时候,千万不要编码。:(</p>