开发者

Simulate server error

开发者 https://www.devze.com 2023-03-14 20:56 出处:网络
I use the App Engine for run my application and want to test how it will handle server errors. Is t开发者_开发问答here any possibility to simulate an error 500 via the WebTest ?I got around it using a

I use the App Engine for run my application and want to test how it will handle server errors. Is t开发者_开发问答here any possibility to simulate an error 500 via the WebTest ?


I got around it using a try except loop.

try:
    self.testapp.get('/')
    self.assertEqual(1, 2, 'GET request should have resulted in a 405 error') # Purposely fail
except webtest.app.AppError:
    pass

Another way is the following:

self.assertEqual("500 Internal Server Error", self.testapp.post('/', params={}, expect_errors=True).status, 'POST Request should have resulted in a 500 error')

Both methods still will cause traceback to appear but the test passes


A 500 error is just what your webapp returns to the client when it gets an uncaught exception. It's not a specific failure - just what it shows to your users when something unexpected goes wrong. Instead, you should unit-test your handlers to ensure they act as expected.

0

精彩评论

暂无评论...
验证码 换一张
取 消