summaryrefslogtreecommitdiff
path: root/tests/test_utils
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2025-06-03 23:20:43 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-06-05 13:49:39 +0200
commitf0a87895ffaf6532a22143b5e2e304c59b7958ae (patch)
tree960dac172abf8eee251ebad1e730a706e5642a26 /tests/test_utils
parent9a3f3b84999878e22021c92f9102707ba2648209 (diff)
Fixed #36435 -- Made CaptureQueriesContext restore reset_queries conditionally.
Diffstat (limited to 'tests/test_utils')
-rw-r--r--tests/test_utils/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index ae123920e0..e468c24727 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -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):