[Django] #27893: Make it possible to disable exception re-raising in test client

13 views
Skip to first unread message

Django

unread,
Mar 2, 2017, 3:01:58 AM3/2/17
to django-...@googlegroups.com
#27893: Make it possible to disable exception re-raising in test client
---------------------------------------------+------------------------
Reporter: Carl Meyer | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27893>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 2, 2017, 7:51:49 AM3/2/17
to django-...@googlegroups.com
#27893: Make it possible to disable exception re-raising in test client
-----------------------------------+--------------------------------------

Reporter: Carl Meyer | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Tim Graham):

Would you consider this a duplicate of #18707? The solution you proposed
about adding an option to `Client` is proposed in comment 1.

--
Ticket URL: <https://code.djangoproject.com/ticket/27893#comment:1>

Django

unread,
Mar 4, 2017, 10:51:50 PM3/4/17
to django-...@googlegroups.com
#27893: Make it possible to disable exception re-raising in test client
-----------------------------------+--------------------------------------

Reporter: Carl Meyer | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/27893#comment:2>

Django

unread,
Mar 6, 2017, 12:23:02 PM3/6/17
to django-...@googlegroups.com
#27893: Make it possible to disable exception re-raising in test client
-----------------------------------+--------------------------------------

Reporter: Carl Meyer | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Carl Meyer):

Yeah, it's a duplicate - thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/27893#comment:3>

Reply all
Reply to author
Forward
0 new messages