1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #36435 -- Made CaptureQueriesContext restore reset_queries conditionally.

This commit is contained in:
Adam Johnson
2025-06-03 23:20:43 +01:00
committed by Sarah Boyce
parent 9a3f3b8499
commit f0a87895ff
2 changed files with 18 additions and 2 deletions

View File

@@ -435,6 +435,14 @@ class CaptureQueriesContextManagerTests(TestCase):
self.assertIn(self.person_pk, captured_queries[0]["sql"])
self.assertIn(self.person_pk, captured_queries[1]["sql"])
def test_with_client_nested(self):
with CaptureQueriesContext(connection) as captured_queries:
Person.objects.count()
with CaptureQueriesContext(connection):
pass
self.client.get(self.url)
self.assertEqual(2, len(captured_queries))
@override_settings(ROOT_URLCONF="test_utils.urls")
class AssertNumQueriesContextManagerTests(TestCase):
@@ -475,6 +483,13 @@ class AssertNumQueriesContextManagerTests(TestCase):
self.client.get(self.url)
self.client.get(self.url)
def test_with_client_nested(self):
with self.assertNumQueries(2):
Person.objects.count()
with self.assertNumQueries(0):
pass
self.client.get(self.url)
@override_settings(ROOT_URLCONF="test_utils.urls")
class AssertTemplateUsedContextManagerTests(SimpleTestCase):