diff options
| author | Claude Paroz <claude@2xlibre.net> | 2017-05-08 09:53:49 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2017-05-20 15:11:09 +0200 |
| commit | 43c65e0eb003b0eed34eae60a9e2292c00d7e4b6 (patch) | |
| tree | 263ae9031baf38dbe1ce6522efcb9b4f21421837 | |
| parent | eb66057c1e7704bc48992ffe35c27554919551c8 (diff) | |
Fixed #28180 -- Numbered queries in assertNumQueries failure output
Thanks Tim Graham for the test part.
| -rw-r--r-- | django/test/testcases.py | 2 | ||||
| -rw-r--r-- | 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): |
