Test client should re-raise exceptions created while rendering a page
|Reported by:||Owned by:||Russell Keith-Magee|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
With the current
django.test.client.Client class it is not possible to inspect an exception created by the code being tested.
For example, a view may raise an exception due to syntax error, malformed input from the test case or for any number of reasons. The exception is handled by Django and a standard error view (either a 500 page or error debug page) is returned with no other indication about the original exception. It is therefore difficult to track down the actual cause of the error.
A simple patch can handle the
got_request_exception signal created by the base handler and capture the actual exception object and it's associated
exc_info. The exception can then be reraised, complete with the original frame/location information, after the handler has finished. The exception can then be inspected by the test case. The standard behaviour of the test case is to print a stack trace to stdout, which is very useful when creating or fixing tests. As the exception location information is not modified, the original cause can be found and fixed.
Change History (7)
comment:2 Changed 10 years ago by
|Triage Stage:||Unreviewed → Ready for checkin|