markwalker, 4 months ago Is there a way to count the number of queries in tests if you're using django's regular built in testcase? I'm too used to pytest these days 🤔 #django
Is there a way to count the number of queries in tests if you're using django's regular built in testcase?
I'm too used to pytest these days 🤔
#django
emattiza, 4 months ago @markwalker You can import CaptureQueriesContext from django.test.utils (assertNumQueries uses this indirectly). Give it a grep on the django github repo and youll find some tests which show a bit how to use it over a connection import.
@markwalker You can import CaptureQueriesContext from django.test.utils (assertNumQueries uses this indirectly). Give it a grep on the django github repo and youll find some tests which show a bit how to use it over a connection import.
markwalker, 4 months ago @emattiza Oo nice, I haven't actually ever dug into how assertNumQueries operates, so that makes sense! Thanks, I'll take a look 👍
@emattiza Oo nice, I haven't actually ever dug into how assertNumQueries operates, so that makes sense!
Thanks, I'll take a look 👍
CodenameTim, 4 months ago @markwalker assertNumQueries https://docs.djangoproject.com/en/5.0/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries
@markwalker assertNumQueries https://docs.djangoproject.com/en/5.0/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries
assertNumQueries
CodenameTim, 4 months ago @markwalker Oh no, that looks like it might be limited to only TransactionTestCase
@markwalker Oh no, that looks like it might be limited to only TransactionTestCase
Add comment