#27893 closed New feature (duplicate)
Make it possible to disable exception re-raising in test client
Reported by: | Carl Meyer | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the Django test client, we connect to the got_request_exception
signal, store any signalled exception on the test client, and then after the response is returned, we check for a signalled exception and re-raise it (https://github.com/django/django/blob/master/django/test/client.py#L492-L495). Fair enough; usually in tests you prefer to have the exception raised instead of just seeing a 500 error.
But there are two problems with this: 1) it's impossible to turn off (and sometimes there are times when you'd want to, e.g. if testing behavior of handle_uncaught_exception
in a custom WSGI handler subclass), and 2) Django has long had an alternate method to do exactly the same thing, the DEBUG_PROPAGATE_EXCEPTIONS
setting.
The setting is much simpler, and it's easy to turn off for a selected test.
I think we should at least provide a way to turn off the test client re-raising behavior (perhaps via a flag set on the client).
I'm tempted to suggest we should also at some point raise a deprecation warning if this flag is not set, suggesting to use DEBUG_PROPAGATE_EXCEPTIONS when running tests instead, and then later remove the test-client re-raising altogether. But removing this bit of code may not be worth the churn of that deprecation.
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Would you consider this a duplicate of #18707? The solution you proposed about adding an option to
Client
is proposed in comment 1.