diff --git a/docs/changes.rst b/docs/changes.rst index 448f8856f..752f9eedb 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -15,6 +15,7 @@ Pending * Toggle tracking the toolbar's queries when using ``debug_toolbar.store.DatabaseStore`` with ``SKIP_TOOLBAR_QUERIES``. * Fixed font family for code blocks and stack traces in the toolbar. +* Added test to confirm Django's ``TestCase.assertNumQueries`` works. 6.1.0 (2025-10-30) ------------------ diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index 889c68b93..70d45c707 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -102,6 +102,17 @@ def test_recording(self): # ensure the stacktrace is populated self.assertTrue(len(query["stacktrace"]) > 0) + def test_assert_num_queries_works(self): + """ + Confirm Django's assertNumQueries and CaptureQueriesContext works + + See https://github.com/django-commons/django-debug-toolbar/issues/1791 + """ + self.assertEqual(len(self.panel._queries), 0) + with self.assertNumQueries(1): + sql_call() + self.assertEqual(len(self.panel._queries), 1) + async def test_recording_async(self): self.assertEqual(len(self.panel._queries), 0)