Pylons / webtest

Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.
https://docs.pylonsproject.org/projects/webtest/en/latest/
Other
336 stars 110 forks source link

Better error reporting for unexpected status #176

Closed merwok closed 7 years ago

merwok commented 7 years ago

Hello! During development, tests fail when the app returns Bad Request instead of OK or Created because of bugs in the code under test. The error message from webtest only shows that 400 != 200, but with django forms or django-rest-framework validators for example, there is more information in the response body, and it is not currently displayed.

Current work-around: change the test to have status=400 and print response.body.

Desired change: change TestApp._check_status so that the message looks like 'Bad response: {} (not {})\n{}'.format(res.status, status, res.body)

(Idea from https://stackoverflow.com/questions/13505778/finding-the-real-error-in-a-webtest-test-failure ; res.body shows all headers and response bytes, which always works compared to res.json for example)

merwok commented 7 years ago

Thanks!