Making assertNumQueries print the list of queries executed on failure
|Reported by:||dominicrodger||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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).
Change History (4)
comment:1 Changed 3 years ago by timo
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted