[Django] #29658: Use unittest.addCleanup to unregister lookups.

6 views
Skip to first unread message

Django

unread,
Aug 10, 2018, 6:57:16 AM8/10/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
------------------------------------------------+------------------------
Reporter: Mads Jensen | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
There are some places in the test suite that follow this pattern:

{{{
try:
CharField.register_lookup(Length)
# some test code
finally:
CharField._unregister_lookup(Length)
}}}

It'd be better to use `unittest.addCleanup` to handle this stuff.

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

Django

unread,
Aug 10, 2018, 7:12:12 AM8/10/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
--------------------------------------+------------------------------------

Reporter: Mads Jensen | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted


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

Django

unread,
Aug 11, 2018, 7:55:33 AM8/11/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Dominic
Type: | White
Cleanup/optimization | Status: assigned

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Dominic White):

* status: new => assigned
* owner: nobody => Dominic White


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

Django

unread,
Aug 18, 2018, 6:33:02 AM8/18/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Dominic
Type: | White
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Srinivas Reddy Thatiparthy):

https://code.djangoproject.com/ticket/29658

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

Django

unread,
Aug 18, 2018, 6:33:34 AM8/18/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Srinivas
Type: | Reddy Thatiparthy
Cleanup/optimization | Status: assigned

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Srinivas Reddy Thatiparthy):

* owner: Dominic White => Srinivas Reddy Thatiparthy


--
Ticket URL: <https://code.djangoproject.com/ticket/29658#comment:4>

Django

unread,
Aug 20, 2018, 5:00:55 AM8/20/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Srinivas
Type: | Reddy Thatiparthy
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* has_patch: 0 => 1


Comment:

The current patch is using a context manager instead of the `try/finally`
method.
Mads, is that something you are comfortable with, or do you still see some
benefit with `addCleanup`?

--
Ticket URL: <https://code.djangoproject.com/ticket/29658#comment:5>

Django

unread,
Aug 21, 2018, 10:49:55 AM8/21/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Srinivas
Type: | Reddy Thatiparthy
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin


Comment:

Patch looks good to me, unless there's some reason to prefer
`addCleanup()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29658#comment:6>

Django

unread,
Aug 21, 2018, 11:15:03 AM8/21/18
to django-...@googlegroups.com
#29658: Use unittest.addCleanup to unregister lookups.
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Srinivas
Type: | Reddy Thatiparthy
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

Using context managers should be fine as well.

--
Ticket URL: <https://code.djangoproject.com/ticket/29658#comment:7>

Django

unread,
Aug 21, 2018, 11:38:55 AM8/21/18
to django-...@googlegroups.com
#29658: Use a context manager to unregister model field lookups in tests

-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Srinivas
Type: | Reddy Thatiparthy
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Tim Graham:

Old description:

> There are some places in the test suite that follow this pattern:
>
> {{{
> try:
> CharField.register_lookup(Length)
> # some test code
> finally:
> CharField._unregister_lookup(Length)
> }}}
>
> It'd be better to use `unittest.addCleanup` to handle this stuff.

New description:

There are some places in the test suite that follow this pattern:

{{{
try:
CharField.register_lookup(Length)
# some test code
finally:
CharField._unregister_lookup(Length)
}}}

It'd be better to use a context manager (`addCleanup()` was originally
proposed) to handle this stuff.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29658#comment:8>

Django

unread,
Aug 21, 2018, 12:18:12 PM8/21/18
to django-...@googlegroups.com
#29658: Use a context manager to unregister model field lookups in tests
-------------------------------------+-------------------------------------
Reporter: Mads Jensen | Owner: Srinivas
Type: | Reddy Thatiparthy
Cleanup/optimization | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"233c70f0479beb3bff9027e6cff680882978fd4d" 233c70f0]:
{{{
#!CommitTicketReference repository=""
revision="233c70f0479beb3bff9027e6cff680882978fd4d"
Fixed #29658 -- Registered model lookups in tests with a context manager.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29658#comment:9>

Reply all
Reply to author
Forward
0 new messages