diff --git a/django/test/testcases.py b/django/test/testcases.py index 4be5baf4b8a..2752fc646b0 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 69a6a721969..06e2ce417c2 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):