gpt4 book ai didi

python - 在 Webtest 测试失败中找到真正的错误

转载 作者:IT老高 更新时间:2023-10-28 21:04:54 28 4
gpt4 key购买 nike

我正在使用 Python 和 Webtest 来测试一个 WSGI 应用程序。我发现处理程序代码中引发的异常往往会被 Webtest 吞噬,然后引发泛型:

AppError: Bad response: 500 Internal Server Error

我如何告诉它引发或打印导致此问题的原始错误?

最佳答案

虽然 clj 的答案确实有效,但您可能仍希望访问测试用例中的响应。为此,您可以在向 TestApp 发出请求时使用 expect_errors=True(来自 webtest documentation),这样就不会引发 AppError。这是一个我预计会出现 403 错误的示例:

# attempt to access secure page without logging in
response = testapp.get('/secure_page_url', expect_errors=True)

# now you can assert an expected http code,
# and print the response if the code doesn't match
self.assertEqual(403, response.status_int, msg=str(response))

关于python - 在 Webtest 测试失败中找到真正的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13505778/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com