From 43c65e0eb003b0eed34eae60a9e2292c00d7e4b6 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 8 May 2017 09:53:49 +0200 Subject: [PATCH] Fixed #28180 -- Numbered queries in assertNumQueries failure output Thanks Tim Graham for the test part. --- django/test/testcases.py | 2 +- tests/test_utils/tests.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 4be5baf4b8..2752fc646b 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -78,7 +78,7 @@ class _AssertNumQueriesContext(CaptureQueriesContext): "%d queries executed, %d expected\nCaptured queries were:\n%s" % ( executed, self.num, '\n'.join( - query['sql'] for query in self.captured_queries + '%d. %s' % (i, query['sql']) for i, query in enumerate(self.captured_queries, start=1) ) ) ) diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 69a6a72196..06e2ce417c 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -323,8 +323,10 @@ class AssertNumQueriesContextManagerTests(TestCase): with self.assertRaises(AssertionError) as exc_info: 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)) + exc_lines = str(exc_info.exception).split('\n') + self.assertEqual(exc_lines[0], '1 != 2 : 1 queries executed, 2 expected') + self.assertEqual(exc_lines[1], 'Captured queries were:') + self.assertTrue(exc_lines[2].startswith('1.')) # queries are numbered with self.assertRaises(TypeError): with self.assertNumQueries(4000):