Hello Don,

Django logs all database queries to the django.db.backends logger. It is not
redirected to STDOUT when using the default settings.LOGGING configuration
but you can enable it yourself[0].

If you wan to assert against a fixed number of queries you can use the
assertNumQueries context manager[1] provided by SimpleTestCase and its
subclasses to do that.

For an easy to setup and per-view breakdown of the number of queries I
suggest you install the django-debug-toolbar[2] and enable the SQL panel.

For more details about optimizing database accesses within a Django project
I suggest you have a look at the dedicated section of the documentation[3].
I've filed a ticket to make sure bulk_update is also mentioned in this 
section
of the documentation.

Cheers,
Simon

[0] https://www.dabapps.com/blog/logging-sql-queries-django-13/
[1] 
https://docs.djangoproject.com/en/2.2/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries
[2] https://django-debug-toolbar.readthedocs.io/en/latest/
[3] https://docs.djangoproject.com/en/2.2/topics/db/optimization/

Le mardi 23 juillet 2019 12:19:03 UTC-4, Don Baldwin a écrit :
>
> I have a function that runs some database queries and updates.  In the 
> test code for that function, I'd like to check out many times the database 
> is actually being hit.  Does Django provide a way to get that information?
>
> Thanks,
> Don
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf8c2c46-40b7-477a-8635-9da5c766bb7d%40googlegroups.com.

Reply via email to