Skip to content

Commit 88c5d37

Browse files
committed
Added test to confirm assertNumQueries
This was confirmed to be a valid test in e7575e8 when it was a known issue.
1 parent 7c0b02b commit 88c5d37

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Pending
1414
* Dropped support for the Python 3.9, it has reached its end of life date.
1515
* Toggle tracking the toolbar's queries when using
1616
``debug_toolbar.store.DatabaseStore`` with ``SKIP_TOOLBAR_QUERIES``.
17+
* Added test to confirm Django's ``TestCase.assertNumQueries`` works.
1718

1819
6.1.0 (2025-10-30)
1920
------------------

tests/panels/test_sql.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ def test_recording(self):
102102
# ensure the stacktrace is populated
103103
self.assertTrue(len(query["stacktrace"]) > 0)
104104

105+
def test_assert_num_queries_works(self):
106+
"""
107+
Confirm Django's assertNumQueries and CaptureQueriesContext works
108+
109+
See https://github.com/django-commons/django-debug-toolbar/issues/1791
110+
"""
111+
self.assertEqual(len(self.panel._queries), 0)
112+
with self.assertNumQueries(1):
113+
sql_call()
114+
self.assertEqual(len(self.panel._queries), 1)
115+
105116
async def test_recording_async(self):
106117
self.assertEqual(len(self.panel._queries), 0)
107118

0 commit comments

Comments
 (0)