[Django] #21462: Making assertNumQueries print the list of queries executed on failure

7 views
Skip to first unread message

Django

unread,
Nov 18, 2013, 2:58:14 PM11/18/13
to django-...@googlegroups.com
#21462: Making assertNumQueries print the list of queries executed on failure
-----------------------------------+--------------------
Reporter: dominicrodger | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
Currently, when assertNumQueries fails, the output is perhaps less helpful
than it might be:

{{{
Traceback (most recent call last):
File
"/home/dom/.virtualenvs/kanisa/src/kanisa/kanisa/tests/views/public.py",
line 31, in test_kanisa_root_view
[banner1.pk, banner2.pk, banner3.pk, banner5.pk, ])
File
"/home/dom/.virtualenvs/kanisa/src/kanisa/.tox/py27-1.5.X/local/lib/python2.7
/site-packages/django/test/testcases.py", line 195, in __exit__
executed, self.num
AssertionError: 5 queries executed, 99 expected
}}}

When an assertNumQueries check fails, the first thing I (and I'd guess
everyone else too) want to know is what queries ran, so it'd be awesome if
an assertNumQueries failure printed the list of queries. Charlie Denton
has a blog post describing how he does this (http://meshy.co.uk/posts
/debugging-assertnumqueries-tests/), but I'd like to see this included in
Django itself - since it seems generally helpful.

This was discussed on django-developers
(https://groups.google.com/forum/#!topic/django-developers/8aUL9d9yyzg).

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

Django

unread,
Nov 19, 2013, 8:24:16 AM11/19/13
to django-...@googlegroups.com
#21462: Making assertNumQueries print the list of queries executed on failure
-----------------------------------+------------------------------------

Reporter: dominicrodger | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by timo):

* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


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

Django

unread,
Dec 8, 2013, 6:10:44 PM12/8/13
to django-...@googlegroups.com
#21462: Making assertNumQueries print the list of queries executed on failure
-----------------------------------+------------------------------------

Reporter: dominicrodger | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by dominicrodger):

Pull request created - https://github.com/django/django/pull/2055.

I'm not sure what kind of testing this needs - I don't want tests to
depend on the SQL generated, so for now I've just amended the test for
this to check that "Captured queries were" is included in the assertion.
That feels a bit limited, so better ideas welcome.

This is my first non-docs contribution to Django, so do let me know if
there's anything else that needs doing to get this committed.

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

Django

unread,
Dec 11, 2013, 3:23:32 PM12/11/13
to django-...@googlegroups.com
#21462: Making assertNumQueries print the list of queries executed on failure
-------------------------------------+-------------------------------------

Reporter: dominicrodger | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 0 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


Comment:

Test is looking good and the full test suite passes on Py2-3 SQlite3. The
added test also passes on PostgreSQL (Py2-3) and MySQL.

Will commit with the minor suggested changes applied.

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

Django

unread,
Dec 11, 2013, 3:24:48 PM12/11/13
to django-...@googlegroups.com
#21462: Making assertNumQueries print the list of queries executed on failure
-------------------------------------+-------------------------------------
Reporter: dominicrodger | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
Has patch: 0 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette <charette.s@…>):

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


Comment:

In [changeset:"5cd6477fd6ea31eeb4d281e8e431b7a5fb8038a1"]:
{{{
#!CommitTicketReference repository=""
revision="5cd6477fd6ea31eeb4d281e8e431b7a5fb8038a1"
Fixed #21462 -- Made `assertNumQueries` print executed queries on failure.
}}}

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

Reply all
Reply to author
Forward
0 new messages