1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Used assertRaisesMessage() in various tests.

This commit is contained in:
Hasan Ramezani
2020-02-04 21:58:07 +01:00
committed by Mariusz Felisiak
parent 71756bdfed
commit fc4f45ebdc
8 changed files with 59 additions and 101 deletions

View File

@@ -374,13 +374,13 @@ class AssertNumQueriesContextManagerTests(TestCase):
Person.objects.count()
def test_failure(self):
with self.assertRaises(AssertionError) as exc_info:
msg = (
'1 != 2 : 1 queries executed, 2 expected\nCaptured queries were:\n'
'1.'
)
with self.assertRaisesMessage(AssertionError, msg):
with self.assertNumQueries(2):
Person.objects.count()
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):