Browse files

Fixed #21462 -- Made `assertNumQueries` print executed queries on fai…

…lure.
  • Loading branch information...
1 parent 75924cf commit 5cd6477fd6ea31eeb4d281e8e431b7a5fb8038a1 @dominicrodger dominicrodger committed with charettes Dec 8, 2013
Showing with 10 additions and 2 deletions.
  1. +6 −2 django/test/testcases.py
  2. +3 −0 docs/releases/1.7.txt
  3. +1 −0 tests/test_utils/tests.py
View
8 django/test/testcases.py
@@ -103,8 +103,12 @@ def __exit__(self, exc_type, exc_value, traceback):
return
executed = len(self)
self.test_case.assertEqual(
- executed, self.num, "%d queries executed, %d expected" % (
- executed, self.num
+ executed, self.num,
+ "%d queries executed, %d expected\nCaptured queries were:\n%s" % (
+ executed, self.num,
+ '\n'.join(
+ query['sql'] for query in self.captured_queries
+ )
)
)
View
3 docs/releases/1.7.txt
@@ -713,6 +713,9 @@ Miscellaneous
``select_related('foo').select_related('bar')``. Previously the latter would
have been equivalent to ``select_related('bar')``.
+* :meth:`~django.test.TransactionTestCase.assertNumQueries` now prints
+ out the list of executed queries if the assertion fails.
+
Features deprecated in 1.7
==========================
View
1 tests/test_utils/tests.py
@@ -192,6 +192,7 @@ def test_failure(self):
with self.assertNumQueries(2):
Person.objects.count()
self.assertIn("1 queries executed, 2 expected", str(exc_info.exception))
+ self.assertIn("Captured queries were", str(exc_info.exception))
with self.assertRaises(TypeError):
with self.assertNumQueries(4000):

0 comments on commit 5cd6477

Please sign in to comment.