Fixed #36435 -- Made CaptureQueriesContext restore reset_queries conditionally.
Some checks are pending
Linters / flake8 (push) Waiting to run
Linters / isort (push) Waiting to run
Linters / black (push) Waiting to run
Tests / Windows, SQLite, Python 3.13 (push) Waiting to run
Tests / JavaScript tests (push) Waiting to run

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):