Opened 4 years ago

Last modified 17 months ago

#18707 new New feature

Test client doesn't allow testing 500 responses content

Reported by: ricardokirkner@… Owned by: nobody
Component: Testing framework Version: 1.6
Severity: Normal Keywords:
Cc: frankoid, d1fffuz0r@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The test client is re-raising almost every single exception (as per, which means there is no way to get the response content back for responses returned by the 500 error handler. This prevents using the test client for testing an important area.

Change History (7)

comment:1 Changed 4 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to New feature

The test client works as documented, so it's not a bug.

In most cases this behavior is more useful then returning getting a generic error page. Using selenium is probably a better choice for testing your 500 pages, but I guess that having an option in the Client class could also be useful.

comment:2 Changed 4 years ago by frankoid

  • Cc frankoid added

comment:3 Changed 3 years ago by d1ffuz0r

  • Cc d1fffuz0r@… added

comment:4 Changed 3 years ago by mjtamlyn

Is there any reason why TemplateView(template_name='500.html') is not sufficient for doing this?

comment:5 Changed 3 years ago by David Avs <david@…>

One reason is that handler500 sometimes could be a custom view. In this case TemplateView(...).as_view() may be not sufficient, but the handler500 can be used instead.

comment:6 Changed 2 years ago by nicbou

  • Version changed from 1.3 to 1.6

I am in the same situation as David. Our 500 page is a redirect that needs to be tested. Although it's a fairly easy to test for 404s and the like, we can't test that our 500 handler works.

comment:7 Changed 17 months ago by spacediver

Hi folks,

Currently I need to test not even 500 user-facing view, but email sending on 500.

Is there any way to trigger production error handling from within unit test with django client (or otherwise from unit test)?

I strongly hesitate to move this into Selenium integration tests due to need of full-fledged email mocking (instead of neat and sweet locmem email backend that I may use in unit tests).


Last edited 17 months ago by spacediver (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top