Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…lure.
  • Loading branch information...
commit 5cd6477fd6ea31eeb4d281e8e431b7a5fb8038a1 1 parent 75924cf
Dominic Rodger dominicrodger authored charettes committed
8 django/test/testcases.py
View
@@ -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
+ )
)
)
3  docs/releases/1.7.txt
View
@@ -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
==========================
1  tests/test_utils/tests.py
View
@@ -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):
Please sign in to comment.
Something went wrong with that request. Please try again.